利用打码平台完成腾讯防水墙滑块验证码
打码平台:图鉴
tu_jian_api.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : CZW
import base64
import json
import requests
# 图鉴账号密码
uname = ""
pwd = ""
def base64_api(img, typeid):
with open(img, 'rb') as f:
base64_data = base64.b64encode(f.read())
b64 = base64_data.decode()
data = {"username": uname, "password": pwd, "typeid": typeid, "image": b64}
result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
if result['success']:
return result["data"]["result"]
else:
return result["message"]
return ""
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : CZW
# 腾讯防水墙-体验用户
import time
from selenium import webdriver
from selenium.webdriver import ActionChains # 动作链
from tu_jian_api import base64_api # 图鉴
# 浏览器对象
driver = webdriver.Chrome()
# 访问登录页
driver.get("https://007.qq.com/online.html")
# 点击 体验用户
driver.find_element_by_xpath('//div[@class="wp-onb-tit"]/a[@data-type="1"]').click()
# 点击登录
driver.find_element_by_xpath('//button[@id="code"]').click()
time.sleep(3)
# 找到弹出验证码框的节点元素
iframe = driver.find_element_by_xpath('//iframe[@id="tcaptcha_iframe"]')
driver.switch_to.frame(iframe)
yzm_element = driver.find_element_by_xpath('//div[@id="slideBgWrap"]')
time.sleep(1)
# 保存截取验证码框的图片
yzm_element.screenshot("tx_007_yzm.png")
# 图鉴打码
code_result = int(base64_api(r"./tx_007_yzm.png", 33)) - 35
print("坐标", code_result)
# 定位滑块
element = driver.find_element_by_xpath('//div[@id="tcaptcha_drag_thumb"]')
# 按住滑块
ActionChains(driver).click_and_hold(on_element=element).perform()
ActionChains(driver).move_by_offset(xoffset=code_result, yoffset=0).perform()
# 释放鼠标
time.sleep(1)
ActionChains(driver).release().perform()