当前位置:网站首页>Slider validation code
Slider validation code
2022-06-29 09:48:00 【qq_ forty-three million six hundred and fourteen thousand three】
This article is from the Internet , Any infringement can be deleted at any time
The import module
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 # Slide a little bit , And finally slide back
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))
# Slide backwards to the exact position
back_tracks = [-1, -1, -1, -2, -3, -2, -2, -2, -2, -1, -1, -1] # The total is equal to -20
return {'forward_tracks':forward_tracks, 'back_tracks':back_tracks}
def crack(driver): # Crack sliding authentication
# 1. Click button , Get a picture with no gaps
button = driver.find_element_by_class_name(‘geetest_radar_tip’)
button.click()
# 2. Get pictures without gaps
image1 = get_image(driver)
# 3. Click the slide button , Get a picture with a gap
button = driver.find_element_by_class_name('geetest_slider_button')
button.click()
# 4. Get pictures with gaps
image2 = get_image(driver)
# 5. Compare the pixels of the two pictures , Find the displacement
distance = get_distance(image1, image2)
# 6. Simulate people's behavior habits , The behavior trace obtained from the total displacement
tracks = get_tracks(distance)
print(tracks)
# 7. First slide forward according to the human action track , Rear reverse slide
button = driver.find_element_by_class_name('geetest_slider_button')
ActionChains(driver).click_and_hold(button).perform()
# Normal humans always start sliding forward with confidence , The expression of self-confidence is crazy acceleration
for track in tracks['forward_tracks']:
ActionChains(driver).move_by_offset(xoffset=track, yoffset=0).perform()
# It turned out to be stupid , A normal human pauses , Come to your senses and find , Oh my god , It slipped , Then start sliding in the opposite direction
time.sleep(0.3)
for back_track in tracks['back_tracks']:
ActionChains(driver).move_by_offset(xoffset=back_track, yoffset=0).perform()
# A small shock , Further confuse the background of the extreme experience , This step can greatly improve the success rate
time.sleep(0.1)
ActionChains(driver).move_by_offset(xoffset=-3, yoffset=0).perform()
ActionChains(driver).move_by_offset(xoffset=3, yoffset=0).perform()
# After success , People like to enjoy the results of their puzzles in silence , Then reluctantly release the dirty hand
time.sleep(0.5)
ActionChains(driver).release().perform()
def login_cnblogs(username,password):
driver = webdriver.Chrome()
try:
# 1、 Enter the account and password and press enter
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 sliding authentication
crack(driver)
time.sleep(10) # Sleep longer , Confirm that the login is successful
finally:
driver.close()
if name == ‘main’:
login_cnblogs(username=‘aaaaa’,password=‘aaaaa’)
边栏推荐
- After aikuai is installed or reset, the PC or mobile terminal cannot obtain IP
- User level threads and kernel level threads
- 1424. diagonal traversal II
- Leetcode skimming -- teponacci sequence
- Idea auto completion
- 【技术开发】酒精测试仪解决方案开发设计
- Matlab tips (21) matrix analysis -- partial least squares regression
- Western Polytechnic University, one of the "seven national defense schools", was attacked by overseas networks
- 监控数据源连接池使用情况
- 商业智能BI的未来,如何看待AI+BI这种模式?
猜你喜欢

UE4 在4.20-23版本安装Datasmith插件

基於PyQt5和Qt Designer的簡易加法計算器的制作

Do you know what BFD is? This article explains the principle and usage scenarios of BFD protocol in detail

Visual assist plug-in settings for UE4 vs

easyexecl导出100万行execl报字体错误的解决办法

How to do unit test well

UE4 blueprint modify get a copy in array to reference

Summary of 3DMAX jamming, white screen and rendering crash

A comparison of methods for fully automatic segmentation of tumors and involved nodes in PET/CT of h

UE4 VS的Visual Assist插件设置
随机推荐
Uber 前安全主管面临欺诈指控,曾隐瞒数据泄露事件
Invalidconnectionattributeexception exception exception handling
c#判断数组是否包含另一个数组的任何项
Mysql配置主从数据库
《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(五)
Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
Mysql database and table splitting strategy and application scenarios
UE4 在4.20-23版本安裝Datasmith插件
How to set Google Chrome as the default browser
你必须知道的23个最有用的Elasticseaerch检索技巧
IDEA自动补全
LC236. 二叉树的最近公共祖先
The former security director of Uber faced fraud allegations and concealed the data leakage event
Introduction to Chang'an chain data storage and construction of MySQL storage environment
Leetcode skimming -- teponacci sequence
Chapter 12 signals (II) - examples of producers and consumers
Iso16000-9 testing of volatile organic compounds in building products and furniture
Easyexcl export 1million lines of EXECL report font error solution
数据治理:元数据管理(第二篇)
爱快安装或重置后,PC或手机端获取不到ip