captcha_qq
腾讯防水墙滑动验证码破解
* 使用OpenCV库
* 成功率大概90%左右:在实际应用中,登录后可判断当前页面是否有登录成功才会出现的信息:比如用户名等。循环
* 验证码地址:https://open.captcha.qq.com/online.html
* 破解 腾讯滑动验证码
* 腾讯防水墙
* python + seleniuum + cv2
结果展示
这里有一点很有意思
- 如果滑动过快或者滑动的又精确又快的话,有时会解锁不成功,所以这里使用了 模拟人滑动的方法:
- 加速度,多滑,划回来等 各种操作,各位也可以多试试。
def get_track(distance):
"""
模拟轨迹 假装是人在操作
:param distance:
:return:
"""
v = 0
t = 0.2
tracks = []
current = 0
mid = distance * 7 / 8
distance += 10
while current < distance:
if current < mid:
a = random.randint(2, 4)
else:
a = -random.randint(3, 5)
v0 = v
s = v0 * t + 0.5 * a * (t ** 2)
current += s
tracks.append(round(s))
v = v0 + a * t
for i in range(4):
tracks.append(-random.randint(2, 3))
for i in range(4):
tracks.append(-random.randint(1, 3))
return tracks
代码在这里
- star 一下
- 项目地址 https://github.com/ybsdegit/captcha_qq
- 入口代码地址 https://github.com/ybsdegit/captcha_qq/blob/master/captcha_qq.py
这里是代码
import numpy as np
import random
import requests
from selenium.webdriver import ActionChains
import time
from selenium import webdriver
from PIL import Image
import os
from selenium.webdriver.support.ui import WebDriverWait
import cv2
class Login(object):
"""
腾讯防水墙滑动验证码破解
使用OpenCV库
成功率大概90%左右:在实际应用中,登录后可判断当前页面是否有登录成功才会出现的信息:比如用户名等。循环
https://open.captcha.qq.com/online.html
破解 腾讯滑动验证码
腾讯防水墙
python + seleniuum + cv2
"""
def __init__(self):
self.url = "https://open.captcha.qq.com/online.html"
self.driver = webdriver.Chrome()
@staticmethod
def show(name):
cv2.imshow('Show', name)
cv2.waitKey(0)
cv2.destroyAllWindows()
@staticmethod
def webdriverwait_send_keys(dri, element, value):
"""
显示等待输入
:param dri: driver
:param element:
:param value:
:return:
"""
WebDriverWait(dri, 10, 5).until(lambda dr: element).send_keys(value)
@staticmethod
def webdriverwait_click(dri, element):
"""
显示等待 click
:param dri: driver
:param element:
:return:
"""
WebDriverWait(dri, 10, 5).until(lambda dr: element).click()
@staticmethod
def get_postion(chunk, canves):
"""
判断缺口位置
:param chunk: 缺口图片是原图
:param canves:
:return: 位置 x, y
"""
otemp = chunk
oblk = canves
target = cv2.imread(otemp, 0)
template = cv2.imread(oblk, 0)
temp = 'temp.jpg'
targ = 'targ.jpg'
cv2.imwrite(temp, template)
cv2.imwrite(targ, target)
target = cv2.imread(targ)
target = cv2.cvtColor(target, cv2.COLOR_BGR2GRAY)
target = abs(255 - target)
cv2.imwrite(targ, target)
target = cv2.imread(targ)
template = cv2.imread(temp)
result = cv2.matchTemplate(target, template, cv2.TM_CCOEFF_NORMED)
x, y = np.unravel_index(result.argmax(), result.shape)
return x, y
@staticmethod
def get_track(distance):
"""
模拟轨迹 假装是人在操作
:param distance:
:return:
"""
v = 0
t = 0.2
tracks = []
current = 0
mid = distance * 7 / 8
distance += 10
while current < distance:
if current < mid:
a = random.randint(2, 4)
else:
a = -random.randint(3, 5)
v0 = v
s = v0 * t + 0.5 * a * (t ** 2)
current += s
tracks.append(round(s))
v = v0 + a * t
for i in range(4):
tracks.append(-random.randint(2, 3))
for i in range(4):
tracks.append(-random.randint(1, 3))
return tracks
@staticmethod
def urllib_download(imgurl, imgsavepath):
"""
下载图片
:param imgurl: 图片url
:param imgsavepath: 存放地址
:return:
"""
from urllib.request import urlretrieve
urlretrieve(imgurl, imgsavepath)
def after_quit(self):
"""
关闭浏览器
:return:
"""
self.driver.quit()
def login_main(self):
driver = self.driver
driver.maximize_window()
driver.get(self.url)
click_keyi_username = driver.find_element_by_xpath("//div[@class='wp-onb-tit']/a[text()='可疑用户']")
self.webdriverwait_click(driver, click_keyi_username)
login_button = driver.find_element_by_id('code')
self.webdriverwait_click(driver, login_button)
time.sleep(1)
driver.switch_to.frame(driver.find_element_by_id('tcaptcha_iframe'))
time.sleep(0.5)
bk_block = driver.find_element_by_xpath('//img[@id="slideBg"]')
web_image_width = bk_block.size
web_image_width = web_image_width['width']
bk_block_x = bk_block.location['x']
slide_block = driver.find_element_by_xpath('//img[@id="slideBlock"]')
slide_block_x = slide_block.location['x']
bk_block = driver.find_element_by_xpath('//img[@id="slideBg"]').get_attribute('src')
slide_block = driver.find_element_by_xpath('//img[@id="slideBlock"]').get_attribute('src')
slid_ing = driver.find_element_by_xpath('//div[@id="tcaptcha_drag_thumb"]')
os.makedirs('./image/', exist_ok=True)
self.urllib_download(bk_block, './image/bkBlock.png')
self.urllib_download(slide_block, './image/slideBlock.png')
time.sleep(0.5)
img_bkblock = Image.open('./image/bkBlock.png')
real_width = img_bkblock.size[0]
width_scale = float(real_width) / float(web_image_width)
position = self.get_postion('./image/bkBlock.png', './image/slideBlock.png')
real_position = position[1] / width_scale
real_position = real_position - (slide_block_x - bk_block_x)
track_list = self.get_track(real_position + 4)
ActionChains(driver).click_and_hold(on_element=slid_ing).perform()
time.sleep(0.2)
for track in track_list:
ActionChains(driver).move_by_offset(xoffset=track, yoffset=0).perform()
time.sleep(0.002)
time.sleep(1)
ActionChains(driver).release(on_element=slid_ing).perform()
time.sleep(1)
print('登录成功')
self.after_quit()
if __name__ == '__main__':
phone = "****"
login = Login()
login.login_main()