Esempio n. 1
0
 def captcha(self):
     '''
     可改写验证码的获取方式,此处使用打码平台识别验证码
     :return:
     '''
     api = FateadmApi(app_id="", app_key="", pd_id="", pd_key="")
     captcha = api.PredictFromFile("20400", "captcha.png").pred_rsp.value
     return captcha
Esempio n. 2
0
def cookie_init():
	retries = 1
	while retries < 3:
		cookie = {}
		headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/65.0.3325.181 Safari/537.36'}
		chrome_options = webdriver.ChromeOptions()
		chrome_options.add_argument('--headless')
		chrome_options.add_argument('--disable-gpu')
		chrome_options.add_argument('--no-sandbox')
		chrome_options.add_argument('--disable-dev-shm-usage')
		client = webdriver.Chrome(options=chrome_options)
		client.get("https://weixin.sogou.com/antispider/?from=%2fweixin%3Ftype%3d2%26query%3d360CERT")
		path = './1.png'
		imgpath = './yzm.png'
		client.get_screenshot_as_file(path)
		im = Image.open(path)
		box = (705, 598, 900, 680)  # 设置要裁剪的区
		region = im.crop(box)
		region.save(imgpath)
		capt = client.find_element_by_xpath('//*[@id="seccodeInput"]')
		test = FateadmApi('','','','')  #打码平台接口
		code = test.PredictFromFile('30600','./yzm.png')  #打码平台识别
		#code = '123456'
		print(code)
		capt.send_keys(code)
		time.sleep(1)
		client.find_element_by_xpath('//*[@id="submit"]').click()
		time.sleep(2)
		#print(new_html)
		for item in client.get_cookies():
		    cookie[item["name"]] = item["value"]
		try:
			print(cookie['SNUID'])
		except Exception:
			print ("解锁失败。重试次数:{0:d}".format(3-retries))
			retries += 1
			continue
		time.sleep(5)
		return cookie['SNUID']