【2019.05】腾讯防水墙滑动验证码破解python+selenium+OpenCV
【2019.05】腾讯防⽔墙滑动验证码破解python+selenium+OpenCV captcha_qq
腾讯防⽔墙滑动验证码破解
* 使⽤OpenCV库
* 成功率⼤概90%左右:在实际应⽤中,登录后可判断当前页⾯是否有登录成功才会出现的信息:⽐如⽤户名等。循环
* 验证码地址:open.captcha.qq/online.html
* 破解腾讯滑动验证码
* 腾讯防⽔墙
* python + seleniuum + cv2
结果展⽰
这⾥有⼀点很有意思
如果滑动过快或者滑动的⼜精确⼜快的话,有时会解锁不成功,所以这⾥使⽤了 模拟⼈滑动的⽅法:
加速度,多滑,划回来等 各种操作,各位也可以多试试。
def get_track(distance):
"""
模拟轨迹假装是⼈在操作
:param distance:
:return:
"""
# 初速度
v =0
# 单位时间为0.2s来统计轨迹,轨迹即0.2内的位移
t =0.2
# 位移/轨迹列表,列表内的⼀个元素代表0.2s的位移
tracks =[]
# 当前的位移
current =0
# 到达mid值开始减速
mid = distance *7/8
distance +=10# 先滑过⼀点,最后再反着滑动回来
# a = random.randint(1,3)
while current < distance:
if current < mid:
# 加速度越⼩,单位时间的位移越⼩,模拟的轨迹就越多越详细                a = random.randint(2,4)# 加速运动
else:
a =-random.randint(3,5)# 减速运动
# 初速度
v0 = v
# 0.2秒时间内的位移
s = v0 * t +0.5* a *(t **2)
# 当前的位置
current += s
# 添加到轨迹列表
tracks.append(round(s))
# 速度已经达到v,该速度作为下次的初速度
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 ⼀下
项⽬地址
⼊⼝代码地址
这⾥是代码
#!/usr/bin/env python
什么口红比较好# encoding: utf-8
# -*- coding: utf-8 -*-
# @contact: ybsdeyx@foxmail
# @software: PyCharm
# @time: 2019/4/25 16:39
# @author: Paulson●Wier
# @file: captcha_qq.py
# @desc:
import numpy as np
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%左右:在实际应⽤中,登录后可判断当前页⾯是否有登录成功才会出现的信息:⽐如⽤户名等。循环    open.captcha.qq/online.html
破解腾讯滑动验证码
腾讯防⽔墙
python + seleniuum + cv2
"""
def__init__(self):
# 如果是实际应⽤中,可在此处账号和密码
self.url ="open.captcha.qq/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:
江苏2019高考分数线: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)
# w, h = target.shape[::-1]
离婚了户口可以独立吗
temp ='temp.jpg'
targ ='targ.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
# # 展⽰圈出来的区域
# angle(template, (y, x), (y + w, x + h), (7, 249, 151), 2)
# cv2.imwrite("yuantu.jpg", template)
# show(template)
@staticmethod
def get_track(distance):
"""
模拟轨迹假装是⼈在操作
:param distance:
:return:
"""
# 初速度
v =0
# 单位时间为0.2s来统计轨迹,轨迹即0.2内的位移
t =0.2
# 位移/轨迹列表,列表内的⼀个元素代表0.2s的位移
tracks =[]伪装者剧情介绍
# 当前的位移
current =0
# 到达mid值开始减速
mid = distance *7/8
distance +=10# 先滑过⼀点,最后再反着滑动回来
# a = random.randint(1,3)
while current < distance:
if current < mid:
# 加速度越⼩,单位时间的位移越⼩,模拟的轨迹就越多越详细
a = random.randint(2,4)# 加速运动
else:
a =-random.randint(3,5)# 减速运动
# 初速度
v0 = v
# 0.2秒时间内的位移
s = v0 * t +0.5* a *(t **2)
龙谷山庄# 当前的位置
current += s
# 添加到轨迹列表
tracks.append(round(s))
# 速度已经达到v,该速度作为下次的初速度
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:
"""
quest import urlretrieve
urlretrieve(imgurl, imgsavepath)
def after_quit(self):
"""
关闭浏览器
:return:
"""
self.driver.quit()
def login_main(self):
# ssl._create_default_https_context = ssl._create_unverified_context
driver = self.driver
driver.maximize_window()
<(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'))# switch 到滑块frame
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')# ⼤图 url
slide_block = driver.find_element_by_xpath('//img[@id="slideBlock"]').get_attribute('src')# ⼩滑块图⽚url
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 = _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 = _track(real_position +4)
ActionChains(driver).click_and_hold(on_element=slid_ing).perform()# 点击⿏标左键,按住不放
time.sleep(0.2)
# print('第⼆步,拖动元素')
for track in track_list:
ActionChains(driver).move_by_offset(xoffset=track, yoffset=0).perform()# ⿏标移动到距离当前位置(x,y)
time.sleep(0.002)
# ActionChains(driver).move_by_offset(xoffset=-random.randint(0, 1), yoffset=0).perform()  # 微调,根据实际情况微调        time.sleep(1)
# print('第三步,释放⿏标')
ActionChains(driver).release(on_element=slid_ing).perform()
time.sleep(1)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。