def recognize_code(self): chaojiying = Chaojiying_Client('17709608161', 'a17709608161.', '897923') im = open('code.png', 'rb').read() code_data = chaojiying.PostPic(im, 1902) code = code_data['pic_str'] return code
def __init__(self): self.url_one = 'https://www.tianyancha.com/' # self.url_two = 'https://www.tianyancha.com/search?key=郑州宇通集团有限公司' self.url_two = 'https://antirobot.tianyancha.com/captcha/verify?return_url=https%3A%2F%2Fwww.tianyancha.com%2Fcompany%2F3105819146&rnd=' self.browser = webdriver.Chrome(r"D:\chromedriver.exe") self.wait = WebDriverWait(self.browser, 20) self.email = EMAIL self.password = PASSWORD self.chaojiying = Chaojiying_Client(CHAOJIYING_USERNAME, CHAOJIYING_PASSWORD, CHAOJIYING_SOFT_ID) self.sleep_time = random.uniform(1, 2) self.cookie_one = { 'domain': '.tianyancha.com', "name": "tyc-user-info", "value": "=%257B%2522claimEditPoint%2522%253A%25220%2522%252C%2522myQuestionCount%2522%253A%25220%2522%252C%2522explainPoint%2522%253A%25220%2522%252C%2522nickname%2522%253A%2522%25E4%25BB%25BB%25E7%259B%2588%25E7%259B%2588%2522%252C%2522integrity%2522%253A%25220%2525%2522%252C%2522state%2522%253A%25220%2522%252C%2522announcementPoint%2522%253A%25220%2522%252C%2522vipManager%2522%253A%25220%2522%252C%2522discussCommendCount%2522%253A%25221%2522%252C%2522monitorUnreadCount%2522%253A%252228%2522%252C%2522onum%2522%253A%25220%2522%252C%2522claimPoint%2522%253A%25220%2522%252C%2522token%2522%253A%2522eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxODczOTEzODc4MiIsImlhdCI6MTU0Njk5NTYwMiwiZXhwIjoxNTYyNTQ3NjAyfQ.BEouV6Vs2qq1hehuxwuXXYcmQO9C2BZa1GMfVEYIhQasu8mMwr3IqxE_bzK2ENU0OGltFK3X8dBkBxxW4IzzqQ%2522%252C%2522redPoint%2522%253A%25220%2522%252C%2522pleaseAnswerCount%2522%253A%25221%2522%252C%2522bizCardUnread%2522%253A%25220%2522%252C%2522vnum%2522%253A%25220%2522%252C%2522mobile%2522%253A%252218739138782%2522%257D" } self.cookie_two = { 'domain': '.tianyancha.com', "name": "auth_token", "value": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxODczOTEzODc4MiIsImlhdCI6MTU0Njk5NTYwMiwiZXhwIjoxNTYyNTQ3NjAyfQ.BEouV6Vs2qq1hehuxwuXXYcmQO9C2BZa1GMfVEYIhQasu8mMwr3IqxE_bzK2ENU0OGltFK3X8dBkBxxW4IzzqQ" } self.suijishu = random.uniform(1, 2)
def get_position(self): """通过超级鹰得到坐标""" self.get_captcha() time.sleep(0.2) chaojiying = Chaojiying_Client('vivi9310', 'bulibuqi1314', '899845') im = open('screenshot.png', 'rb').read() return chaojiying.PostPic(im, 9103)
def __init__(self): self.apper = Apper(platformName, platformVersion, deviceName, appPackage, appActivity) self.driver = self.apper.driver # 打码平台客户端 self.chaojiying = Chaojiying_Client('用户名', '密码', '软件id') self.logger = MyLogger('weibo', './weibog_log.txt')
def process_response(self, request, response, spider): ''' 对拉勾网重定向302的解决,捕捉到302URL,然后进行处理 ''' re_match = re.match('.*?/utrack/verify.*', response.url) if re_match: url = re_match.group(0) # 向302URL发起请求,识别验证码,并继续访问 spider.browser.get(url) while True: selector = Selector(text=spider.browser.page_source) captcha_url = selector.css( '#captcha::attr(src)').extract_first('') if not captcha_url: break captcha_url = "https://www.lagou.com" + captcha_url image = requests.get(captcha_url) chaojiying = Chaojiying_Client('Yanxueshan', 'lingtian..1021', '898966') result = chaojiying.PostPic(image.content, 1005)['pic_str'] spider.browser.find_element_by_css_selector("#code").send_keys( result) spider.browser.find_element_by_css_selector("#submit").click() return HtmlResponse(url=spider.browser.current_url, body=spider.browser.page_source, encoding="utf-8", request=request) return response
def pic_post(self, img_post): cjy = Chaojiying_Client(self.user, self.pw, self.id) x = cjy.PostPic(img_post, 9103).get('pic_str') print(x) position = [i.split(',') for i in (x.split('|'))] print(position) return position
def __init__(self): self.chrome = webdriver.Chrome() self.Chojiying_client = Chaojiying_Client(username=chaojiying_user, password=chaojiying_pwd, soft_id=soft_id) self.user = '******' self.password = '******'
def get_image_code(self,image_base64_str): self.logger.mccWriteLog("开始识别验证码") try: #尝试三次进行识别,如果三次识别都失败则返回"" chaojiying = Chaojiying_Client(self.accounts.get("username"),md5(self.accounts.get("password")).hexdigest(),self.accounts.get("soft_id")) times = self.cfReader.readConfig("SYS","times") result = "" if image_base64_str is not None and len(image_base64_str)>0: start_time = datetime.now() #替换base64多余的字符 replace_str = image_base64_str.replace(self.cfReader.readConfig("IMAGEREG","reg"), "") self.logger.mccWriteLog("验证码替换字符串规则{}".format(self.cfReader.readConfig("IMAGEREG","reg"))) self.logger.mccWriteLog("验证码识别前为{}".format(replace_str)) content = base64.b64decode(replace_str) for i in range(int(times)): self.logger.mccWriteLog("开始识别验证码{}次".format(str(i+1))) result_dict = chaojiying.PostPic(content, self.cfReader.readConfig("IMAGETYPE","code")) self.logger.mccWriteLog("识别验证码结果{}".format(str(result_dict))) tag = result_dict.get("err_str") == u'OK' if tag: result = result_dict.get('pic_str') end_time= datetime.now() diff = (end_time - start_time).seconds self.logger.mccWriteLog("{}次识别验证码成功:{}\n耗时{}秒.".format(str(i),str(result),str(diff))) break else: self.logger.mccError("{}次识别验证码失败:{}".format(str(i+1), str(result))) time.sleep(2) return result except Exception,e: self.logger.mccError("验证码识别错误:"+str(e))
def login(self): login_url = 'https://www.dszuqiu.com/w_login' captcha_url = 'https://www.dszuqiu.com/captcha' resp = self.session.get(captcha_url, headers=self.headers, timeout=30, verify=False) logger.info(resp.status_code) path = os.path.dirname(os.path.abspath(__file__)) open(f"{path}/img/football.png", 'wb').write(resp.content) im = open(f'{path}/img/football.png', 'rb').read() chaojiying = Chaojiying_Client() code = chaojiying.PostPic(im, 1006) result = code["pic_str"].lower() logger.info('验证码识别结果为:') logger.info(result) #表单 data = { "zhanghu": '*****@*****.**', "password": '******', "captcha_input": result, "rememberMe": '1', "is_ajax": '1' } response = self.session.post(login_url, headers=self.headers, data=data) logger.info(response.status_code) cookie = requests.utils.dict_from_cookiejar(self.session.cookies) return cookie
def login(url): # 实例化一个driver with webdriver.Chrome(options=options) as driver: driver.get(url) # 发送请求 driver.find_element_by_class_name('login-hd-account').click() # 切换到账号登录 driver.fullscreen_window() # 全屏显示 loginImg = WebDriverWait(driver,5,0.2).until( # 显示等待5秒,直到验证码加载出来 EC.presence_of_element_located((By.ID,'J-loginImg')) ) ImgSize = loginImg.rect # 获取验证码的尺寸和位置 driver.save_screenshot('12306.png') # 将整个页面截屏保存 rangle = (ImgSize['x'],ImgSize['y'],ImgSize['x']+ImgSize['width'],ImgSize['y']+ImgSize['height']) frame = Image.open('12306.png').crop(rangle) # 通过验证码的左上角和右下角坐标,截屏验证码图片 frame.save('code.png') # 保存验证码图片 # 使用超级鹰识别出验证码中待点击个图的位置 cjy = Chaojiying_Client('超级鹰账户', '超级鹰密码', '913533') im = open('code.png', 'rb').read() result = cjy.PostPic(im, 9004)['pic_str'] # ‘96,23|67,11’ points = process_site(result) # 处理成[[‘96‘,‘23’],[‘67’,‘11’]] print(points) driver.find_element_by_id('J-userName').send_keys('账户') # 输入账户 time.sleep(1) driver.find_element_by_id('J-password').send_keys('密码') # 输入密码 time.sleep(1) # 依次找到识别物并点击 for l in points: x = int(l[0]) y = int(l[1]) ActionChains(driver).move_to_element_with_offset(loginImg,x,y).click().perform() time.sleep(1) driver.find_element_by_id('J-login').click() # 点击登录按钮 time.sleep(3)
def post_captcha(self,captcha): cjy = Chaojiying_Client(self.un, self.pw, self.soft_id) result = cjy.PostPic(captcha, 9103).get('pic_str') print(result) position = [i.split(',')for i in result.split('|')] return position
def __init__(self): chrome_option = webdriver.ChromeOptions() self.driver = webdriver.Chrome( executable_path= r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe", chrome_options=chrome_option) self.driver.set_window_size(1440, 900) self.wait = WebDriverWait(self.driver, 10) self.cookie_url = 'http://www.gsxt.gov.cn/index.html' self.post_url = 'http://www.gsxt.gov.cn/corp-query-search-1.html' self.session = requests.Session() self.refer_url = 'http://www.gsxt.gov.cn' self.session.headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36' } self.chaojiying = Chaojiying_Client(CHAOJIYING_USERNAME, CHAOJIYING_PASSWORD, CHAOJIYING_SOFT_ID) self.dbconn = pymysql.connect( host="sh-cdb-khe0u424.sql.tencentcdb.com", db='srtestdb', user='******', password='******', port=62624, charset='utf8') sql = '''select * from HZQY;''' a = pd.read_sql(sql, self.dbconn) self.keys = a['企业名称'] self.cursor = self.dbconn.cursor() #self.searchword = searchword self.detail_list = [] self.table = '企业信息'
def charNum(self, path): chaojiying = Chaojiying_Client('username', 'password', '1902') # 用户中心>>软件ID 生成一个替换 96001 im = open(path, 'rb').read() # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要// mystr = chaojiying.PostPic(im, 1902)['pic_str'] # return mystr return 'word'
def post_captcha_get_position(self, captcha): # 传入超级鹰的账号密码,和软件id client = Chaojiying_Client(self.username, self.password, '896547') # 上传验证码图片,和验证码类型 data = client.PostPic(captcha, '9103') # 字典中的pic_str字段是我们要的汉字坐标,我们用字符串方法分割 position_list = [i.split(',') for i in data.get('pic_str').split('|')] return position_list
def __init__(self): self.url = 'http://admin.touclick.com/login.html' self.browser = webdriver.Chrome() self.wait = WebDriverWait(self.browser, 20) self.email = EMAIL self.password = PASSWORD self.chaojiying = Chaojiying_Client( CHAOJIYING_USERNAME, CHAOJIYING_PASSWORD, CHAOJIYING_SOFT_ID)
def cjy(): chaojiying = Chaojiying_Client('cjyyhmbhf', 'pin86648535', '902284') # 用户中心>>软件ID 生成一个替换 96001 im = open('code.png', 'rb').read() # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要// real = chaojiying.PostPic(im, 1902) with open('pic_text.text', mode='w', encoding='utf_8') as f: f.write(str(real)) return real
def __init__(self): self._url = 'https://kyfw.12306.cn/otn/login/init' self._browser = webdriver.Chrome() self._wait = WebDriverWait(self._browser, 20) self._username = USERNAME self._password = PASSWORD self._chaojiying = Chaojiying_Client(CHAOJIYING_USER, CHAOJIYING_PSW, CHAOJIYING_SOFT_ID) self._pic_id = None
def __init__(self): self.url = 'https://kyfw.12306.cn/otn/resources/login.html' self.browser = webdriver.Chrome() self.wait = WebDriverWait(self.browser, 20) self.email = USERNAME self.password = PASSWORD self.chaojiying = Chaojiying_Client(CHAOJIYING_USER, CHAOJIYING_PSW, CHAOJIYING_SOFT_ID) self.pic_id = None
def __init__(self): self.url = 'https://kyfw.12306.cn/otn/resources/login.html' self.browser = webdriver.Firefox() self.wait = WebDriverWait(self.browser, 10) self.email = EMAIL self.password = PASSWORD self.chaojiying = Chaojiying_Client(CHAOJIYING_USERNAME, CHAOJIYING_PASSWORD, CHAOJIYING_SOFT_ID)
def fail_to_chaojiying(img_id): """ 超级赢验证失败,反馈回去,将不扣钱 :param img_id: 图片id :return: None """ chaojiying = Chaojiying_Client('超级鹰账号', '密码', '软件ID') result = chaojiying.ReportError(img_id) return result
def test_steps_demo(): browser = webdriver.Safari() chrome_options = Options() # 此步骤很重要,设置为开发者模式,防止被各大网站识别出来使用了Selenium #chrome_options.add_experimental_option('--disable-gpu') time.sleep(1) # 访问登录页面 url = 'https://test-appapis-1.95155.com/lhjh-support-web/website.jsp' time.sleep(2) # 设置界面最大化 browser.maximize_window() browser.get(url) #将当前页面截图保存在当前项目 time.sleep(3) browser.save_screenshot('login.png') #验证码元素 yzm_btn = browser.find_element_by_id('imgCode_img') #打开截图 image = Image.open('login.png') weight, height = image.size box = (weight * 1 / 2 - 50, height * 1 / 2 + 30, weight * 1 / 2 + 350, height * 1 / 2 + 275) print(box, '打印') region = image.crop(box) region.save('yzm.png') #调用超级鹰的方法! chaojiying = Chaojiying_Client('18721221627', 'JABIL12345', '910775') #chaojiying = Chaojiying_Client('超级鹰用户名', '超级鹰密码', '换成自己的id') #打开验证码并且读取数据保存! im = open('yzm.png', 'rb').read() #将要识别的验证码类型传过去---具体验证码类型参考第三方打码平台代码! re = chaojiying.PostPic(im, 4004) print('我是返回数据', re) #返回的数据是个json我们要获取pic_str,这个就是验证码识别的结果! distance = re['pic_str'] print('验证码是', distance) #输入账号 browser.find_element_by_id('userName').send_keys('admin') #输入密码 browser.find_element_by_id('password').send_keys('321') # 在输入框输入验证码 yzm_input = browser.find_element_by_id('imgCode') yzm_input.send_keys(distance) time.sleep(3) #点击登录 browser.find_element_by_id('loginSubmit').click() time.sleep(10) #退出浏览器 browser.quit()
def __init__(self): self.url=url self.chrome=webdriver.Chrome() self.username='******' self.pwd='pwd' script=''' window.navigator.webdriver=undefined ''' self.chrome.execute_script(script) self.Chaojiying=Chaojiying_Client(username='******',password='******',soft_id=901069)
def get_code(): print('解码ing') chaojiying = Chaojiying_Client('username', 'userpasd', 'key') # username超级鹰的用户名 # userpasd密码 # key独有的key im = open('code.png', 'rb').read() code = chaojiying.PostPic(im, 1004)["pic_str"] print(code) return code
def jpg(path, num): params = {'pre': 'login', 'sid': num} url = 'https://www.epwk.com/secode_show.php?' res = requests.Session().get(url=url, params=params, headers=headers) with open(path, 'wb') as f: f.write(res.content) chaojiying = Chaojiying_Client('zjy6622', 'zjy19970927', '901769') im = open(path, 'rb').read() data = chaojiying.PostPic(im, 1902) return data['pic_str']
def distinguish_code(self, code_img_path): chaojiying = Chaojiying_Client('spx888', 'spx2622196135', '907630') # 用户中心>>软件ID 生成一个替换 96001 im = open(code_img_path, 'rb').read() # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要// # 输出是字典类型 verification_dic = chaojiying.PostPic(im, 1902) # 1902 验证码类型 print(verification_dic) result = verification_dic['pic_str'] print('识别验证码为:' + result) # 传入result,调用登录函数 self.login(result)
def __init__(self): self.url = 'https://aq.yy.com/p/reg/account.do?appid=&url=&fromadv=udbclsd_r%27' self.browser = webdriver.Chrome() self.wait = WebDriverWait(self.browser, 20) self.browser.get(self.url) self.browser.switch_to.frame( self.browser.find_element_by_xpath( '//iframe[@frameborder="no" and @scrolling="no"]')) self.chaojiying = Chaojiying_Client(CHAOJIYING_USERNAME, CHAOJIYING_PASSWORD, CHAOJIYING_SOFT_ID)
def get_gap_pic(): """ 通过超级鹰获取缺口位置,返回图片id,如果错误则返回id返题分 :return: 缺口距离 """ chaojiying = Chaojiying_Client('超级鹰账号', '密码', '软件ID') im = open('target.png', 'rb').read() result = chaojiying.PostPic(im, 9101) print(result) gap = int(result.get("pic_str").split(",")[0]) pic_id = result.get('pic_id') return gap, pic_id
def __init__(self, username, password): self.username = username self.password = password self.url = 'https://www.zhihu.com/signin' self.chrome_options = Options() # 知乎可以识别出selenium,使用自己打开的浏览器,添加options,端口为映射端口 self.chrome_options.add_experimental_option('debuggerAddress', '127.0.0.1:9222') self.browser = webdriver.Chrome(chrome_options=self.chrome_options) self.wait = WebDriverWait(self.browser, 10) self.chaojiying = Chaojiying_Client(chaojiying_username, chaojiying_password, chaojiying_soft_id)
def get_yan(self, result): if result['showpin'] == 1: url = 'https://login.sina.com.cn/cgi/pin.php' params = {'r': '83661264', 's': '0', 'p': result['pcid']} resp = self.session.get(url, headers=self.headers, params=params, verify=False) pic = BytesIO(resp.content).getvalue() cjy = Chaojiying_Client('m125705171', 'm1257051717', '898279') yz = cjy.PostPic(pic, 1005) # print(yz) return yz['pic_str'] else: return None
def get_code(): #图形验证码接口 url = "http://icode.renren.com/getcode.do?t=web_login&rnd=%s" % ( random.random()) #发送请求 res = session.get(url, headers=headers) #保存图片 with open('code.jpg', 'wb') as fp: fp.write(res.content) fp.flush() chaojiying = Chaojiying_Client('gaohj5', '12qwaszx', '900304') im = open('code.jpg', 'rb').read() result = chaojiying.PostPic(im, 1902)['pic_str'] print(result) return result