def spot_code(self, balances=False): """ 验证码识别 balances 查询余额 :return: """ # 斐斐打码 print('---验证码识别中---') count = 1 while True: if balances: balance = fateadm_api.TestFunc(balances=True) if balance < 1000: print('余额不足及时充值:{}'.format(balance)) elif balance < 100: print('余额严重不足即将不能使用:{}'.format(balance)) elif balance < 10: print('*' * 30) print('余额不足,请充值:{}'.format(balance)) print('*' * 30) sys.exit() return print('打码平台余额:{}'.format(balance)) rsp = fateadm_api.TestFunc() if count > 3: print('验证码识别失败! 请联系开发者') sys.exit() if not rsp.pred_rsp.value: count += 1 continue return rsp.pred_rsp.value
def get_verify_code(): url = "http://www.miitbeian.gov.cn/getVerifyCode?" + str( random.randint(1, 100)) headers = { 'Accept': "image/webp,image/apng,image/*,*/*;q=0.8", 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "zh-CN,zh;q=0.9,en;q=0.8", 'Cache-Control': "no-cache", 'Connection': "keep-alive", 'DNT': "1", 'Host': "www.miitbeian.gov.cn", 'Pragma': "no-cache", 'Referer': "http://www.miitbeian.gov.cn/icp/publish/query/icpMemoInfo_showPage.action", 'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36", } response = requests_session.get(url, headers=headers) if response.status_code != 200: return with open('code.jpg', 'wb') as file: file.write(response.content) verifyCode = fateadm_api.TestFunc('code.jpg') return verifyCode
def retry_request_captcha(self, phone_number_origin, proxies): phone_number, captcha_hash = self.request_captcha( phone_number_origin.split('|')[1], proxies) rsp = fateadm_api.TestFunc() send_result = self.send_monile_code(captcha_hash, rsp.pred_rsp.value, phone_number, proxies) return send_result
def spot_code(self, login=False, just_flag=False, balances=False): """ 验证码识别 balances 查询余额 :return: """ # 斐斐打码 count = 1 while True: # 余额查询 if balances: balance = fateadm_api.TestFunc(balances=True) if balance < 1000: print('余额不足及时充值:{}'.format(balance)) elif balance < 100: print('余额严重不足即将不能使用:{}'.format(balance)) elif balance < 10: print('*' * 30) print('余额不足,请充值:{}'.format(balance)) print('*' * 30) sys.exit() return print('打码平台余额:{}'.format(balance)) # 调用退款接口 if just_flag: fateadm_api.TestFunc(just_flag=self.rsp) return print('打码平台验证码识别中...') # 判断登录还是查询 if login: rsp = fateadm_api.TestFunc(pred_type_id='304000002') else: rsp = fateadm_api.TestFunc() if count > 3: print('验证码识别失败! 请联系开发者') sys.exit() if not rsp.pred_rsp.value: count += 1 continue # 拷贝验证码图片至新目录 # shutil.copy('./code/code.png', './codes/{}.png'.format(rsp.pred_rsp.value)) self.rsp = rsp print(self.rsp.ret_code, self.rsp.request_id) return rsp.pred_rsp.value
def get_picsnum(session): url = "http://union.sogou.com/validateCode" imgresponse = session.get(url, stream=True) # 以流的方式打开 image = imgresponse.content # print image with open("img.jpg", "wb") as jpg: jpg.write(image) x = fateadm_api.TestFunc() return x
def dowloadimg(name, pwd): session = requests.Session() tm = int(time.time()) url = "https://cas.baidu.com/?action=image2&appid=6&key={}".format(tm) # url="http://cas.baidu.com/?action=image" imgresponse = session.get(url, stream=True) # 以流的方式打开 image = imgresponse.content with open("img.jpg", "wb") as jpg: jpg.write(image) x = fateadm_api.TestFunc() print x get_session(session, x, name, pwd)
def send_request(self, author_num, sort_num): """ :param author_num: 需要点击的车管所名字 :param sort_num: 需要点击的汽车类型名字 :return: 目标网页的html """ if self.url == 'https://sx.122.gov.cn/views/vehxhhdpub.html': self.firefox.refresh() author_num = author_num sort_num = sort_num Select(self.firefox.find_element_by_xpath( '//*[@id="glbm"]')).select_by_visible_text(author_num) Select(self.firefox.find_element_by_xpath( '//*[@id="hpzl"]')).select_by_visible_text(sort_num) # 找到查询的按钮点一下 search_butt = self.firefox.find_element_by_xpath( '//*[@id="formsearch"]/div[2]/div[4]') search_butt.click() try: captcha_image = self.firefox.find_element_by_xpath( "/html/body/div[1]/div/table/tbod" "y/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div/span/img") time.sleep(1) captcha_image.screenshot("/root/test.png") except NoSuchElementException as e: self.firefox.delete_all_cookies() self.firefox.refresh() return self.send_request(author_num, sort_num) captcha_result = fateadm_api.TestFunc() input_box = self.firefox.find_element_by_xpath("//*[@id='csessionid']") input_box.send_keys(captcha_result) # 找到确定按钮 sure_butt = self.firefox.find_element_by_xpath( "/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[3]/td/div/button[1]" ) sure_butt.click() time.sleep(0.6) # 判断是否出现Alert if self.check_alert(): self.check_alert().accept() # 停顿3s,防止请求过多出现滑动验证 time.sleep(3) return self.send_request(author_num, sort_num) # 网站的反爬虫是通过cookie的,每次请求完要清除一下cookie,就只会出现验证码 self.firefox.delete_all_cookies() return self.firefox.page_source
def login_run(self, proxies): phone_number_origin = self.get_phone_number() print("Get new phone_number is ", phone_number_origin) phone_number, captcha_hash = self.request_captcha( phone_number_origin.split('|')[1], proxies) rsp = fateadm_api.TestFunc() send_result = self.send_monile_code(captcha_hash, rsp.pred_rsp.value, phone_number, proxies) while (send_result == 2): fateadm_api.Justice(rsp) send_result = self.retry_request_captcha(phone_number_origin, self.get_ip()) print("[~] Geting phone messsage ....") time.sleep(2) if send_result == 3: print("手机号被冻结, 无法收到消息") self.block_phone_number(phone_number) self.release_phone_number(phone_number) elif type(send_result) == str: break captcha_valid = send_result count = 0 while True: time.sleep(5) message = self.get_phone_message(phone_number) if count == 20: print("超时未收到消息, 手机号错误!") self.block_phone_number(phone_number) self.release_phone_number(phone_number) raise LookupError elif message == 3001 or message == "3001": count += 1 continue else: break message_code = re.findall(r"([\d]{6})", message)[0] print("CAPTCHA_CODE_SUCCESS is " + message_code) return self.get_cookies(phone_number, message_code, captcha_valid, proxies)