当前位置:网站首页>滑块验证代码
滑块验证代码
2022-06-29 08:53:00 【qq_43614355】
本文转自网络,如有侵权可随时删除
导入模块
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from PIL import Image
import time
def get_snap(driver):
driver.save_screenshot(‘full_snap.png’)
page_snap_obj = Image.open(‘full_snap.png’)
return page_snap_obj
def get_image(driver):
img = driver.find_element_by_class_name(‘geetest_canvas_img’)
time.sleep(2)
location = img.location
size = img.size
print(size)
left = location['x']
top = location['y']
right = left+size['width']
bottom = top+size['height']
page_snap_obj = get_snap(driver)
image_obj = page_snap_obj.crop((left, top, right, bottom))
# image_obj.show()
return image_obj
def get_distance(image1, image2):
start = 57
threhold = 60
for i in range(start, image1.size[0]):
for j in range(image1.size[1]):
rgb1 = image1.load()[i, j]
rgb2 = image2.load()[i, j]
res1 = abs(rgb1[0]-rgb2[0])
res2 = abs(rgb1[1]-rgb2[1])
res3 = abs(rgb1[2]-rgb2[2])
# print(res1,res2,res3)
if not (res1 <threhold and res2 <threhold and res3 < threhold):
return i - 7
return i - 7
def get_tracks(distance):
distance += 20 # 先滑过一点, 最后再反着滑动回来
v = 0
t = 0.2
forward_tracks = []
current = 0
mid = distance * 3 / 5
while current < distance:
if current < mid:
a = 2
else:
a = -3
s = v * t + 0.5 * a * (t**2)
v = v + a * t
current += s
forward_tracks.append(round(s))
# 反着滑动到准确位置
back_tracks = [-1, -1, -1, -2, -3, -2, -2, -2, -2, -1, -1, -1] # 总共等于 -20
return {'forward_tracks':forward_tracks, 'back_tracks':back_tracks}
def crack(driver): # 破解滑动认证
# 1.点击按钮,得到没有缺口的图片
button = driver.find_element_by_class_name(‘geetest_radar_tip’)
button.click()
# 2.获取没有缺口的图片
image1 = get_image(driver)
# 3.点击滑动按钮,得到有缺口的图片
button = driver.find_element_by_class_name('geetest_slider_button')
button.click()
# 4.获取有缺口的图片
image2 = get_image(driver)
# 5.对比两种图片的像素点,找出位移
distance = get_distance(image1, image2)
# 6.模拟人的行为习惯,根据总位移得到的行为轨迹
tracks = get_tracks(distance)
print(tracks)
# 7.按照人行动轨迹先正向滑动,后反向滑动
button = driver.find_element_by_class_name('geetest_slider_button')
ActionChains(driver).click_and_hold(button).perform()
# 正常人类总是自信满满地开始正向滑动,自信的表现是疯狂加速
for track in tracks['forward_tracks']:
ActionChains(driver).move_by_offset(xoffset=track, yoffset=0).perform()
# 结果傻逼了,正常的人类停顿了一下,回过神来发现,卧槽,滑过了,然后开始反向滑动
time.sleep(0.3)
for back_track in tracks['back_tracks']:
ActionChains(driver).move_by_offset(xoffset=back_track, yoffset=0).perform()
# 小范围震荡一下, 进一步迷惑极验后台, 这一步可以极大的提高成功率
time.sleep(0.1)
ActionChains(driver).move_by_offset(xoffset=-3, yoffset=0).perform()
ActionChains(driver).move_by_offset(xoffset=3, yoffset=0).perform()
# 成功后,骚包人类总喜欢默默地欣赏一下自己拼图的成果,然后恋恋不舍地松开那只脏手
time.sleep(0.5)
ActionChains(driver).release().perform()
def login_cnblogs(username,password):
driver = webdriver.Chrome()
try:
# 1、输入账号密码回车
driver.implicitly_wait(3)
driver.get(‘https://passport.cnblogs.com/user/signin’)
input_username = driver.find_element_by_id('input1')
input_pwd = driver.find_element_by_id('input2')
signin = driver.find_element_by_id('signin')
input_username.send_keys(username)
input_pwd.send_keys(password)
signin.click()
# 2、破解滑动认证
crack(driver)
time.sleep(10) # 睡时间长一点,确定登录成功
finally:
driver.close()
if name == ‘main’:
login_cnblogs(username=‘aaaaa’,password=‘aaaaa’)
边栏推荐
- Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
- Yotact real-time instance segmentation
- Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks
- LeetCode刷题——泰波那契数列
- UE4 在4.20-23版本安装Datasmith插件
- 数据处理时代,数据质量建设才是企业的生存之道
- KiCad学习笔记--快捷键
- 云管理平台:9大开源云管理平台(CMP)
- Laravel 8 enables the order table to be divided by month level
- 基於PyQt5和Qt Designer的簡易加法計算器的制作
猜你喜欢

Laravel 8 enables the order table to be divided by month level

Western Polytechnic University, one of the "seven national defense schools", was attacked by overseas networks

深卷积神经网络时代的目标检测研究进展

Closed door cultivation (24) shallow understanding of cross domain problems

Segmentation of Head and Neck Tumours Using Modified U-net

UE4 remove the mask transparent white edge in the material

KiCad学习笔记--快捷键

Difference between factory mode and strategy mode

UE4 在viewport视口中显示3D可编辑点

Record the field name dynamically modified by SetData of wechat applet
随机推荐
Laravel 8 enables the order table to be divided by month level
The difference between cokkie and session
LeetCode刷题——泰波那契数列
InvalidConnectionAttributeException异常处理
1.4 regression of machine learning methods
The former security director of Uber faced fraud allegations and had concealed data leakage incidents
UE4 installs the datasmith plug-in in version 4.20-23
Basic operations of MAC MySQL database
云管理平台:OpenStack架构设计及详细解读
Written test question "arrange version numbers from large to small"
GD32F4xx 以太网芯片(enc28j60)驱动移植
Pytorch learning summary - memory cost of operation
基於PyQt5和Qt Designer的簡易加法計算器的制作
Introduction to Chang'an chain data storage and construction of MySQL storage environment
UE4 插件报错 Cannot open include file: ‘ModuleManager.h‘解决
UE4 在4.20-23版本安装Datasmith插件
Wechat applet search keyword highlighting and ctrl+f search positioning
IDEA自动补全
【华为认证】HCIA-DATACOM史上最全精选题库(附答案解析)
Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images