勤杂工

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 

一滑动验证码破解原理

这里使用到了selenium+opencv的知识点

废话不多说放源码

import time
from selenium import webdriver

from slideVerfication import SlideVerificationCode

# 一、打开浏览器,访问QQ空间登录页面
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(5)
driver.get('https://qzone.qq.com/')

# 二、点击账号密码登录
# 2,1切换到登录的iframe中
driver.switch_to.frame('login_frame')
# 2.2 点击
driver.find_element_by_xpath("//a[@id='switcher_plogin']").click()

# 三、输入账号密码,点击登录按钮
# 3.1 定位账号输入框,输入账号
driver.find_element_by_xpath('//*[@id="u"]').send_keys('6787878887')
# 3.2 定位密码输入框,输入密码
driver.find_element_by_xpath('//*[@id="p"]').send_keys('lemonban')
# 3.3 点击登录按钮
driver.find_element_by_xpath('//*[@id="login_button"]').click()

# 四、滑动验证码破解
# 4.1切换到滑动验证码的iframe中
driver.switch_to.frame(driver.find_element_by_id('tcaptcha_iframe'))
# 4.2获取滑块元素
block_ele = driver.find_element_by_id('slideBlock')
# 4.3获取背景图元素
slideBg = driver.find_element_by_id('slideBg')
# 4.4 识别滑动距离
sli = SlideVerificationCode()

dis = sli.get_element_slide_distance(block_ele, slideBg)
# 4.5对滑动的距离进行等比缩放
dis = dis * (280 / 680) - 31
print("滑动的距离", dis)
# 4.6 滑动验证
btn = driver.find_element_by_id('tcaptcha_drag_thumb')
sli.slide_verification(driver, btn, dis)
driver.find_element_by_id('tcaptcha_drag_thumb')
# 5秒之后关闭浏览器
time.sleep(5)
driver.quit()

对于不能直接获得背景图,需要使用js的方法来获取对应的图片
def save_img(img_name,class_name):
# img_name 是保存图片的名字,class_name 是需要保存的canvas的className
getImgJS = 'return document.getElementsByClassName("'+ class_name +'")[0].toDataURL("image/png");'
img =driver.execute_script(getImgJS)
base64_data_img = img[img.find(',') + 1:]
image_base = base64.b64decode(base64_data_img)
file = open(img_name, 'wb')
file.write(image_base)
file.close()
这样只需要将背景图和小图的class——name 放进去就好了
save_img('full.jpg', 'geetest_canvas_bg')
save_img('cut.jpg', 'geetest_canvas_slice')

参考博客:https://blog.csdn.net/qq_28654919/article/details/89923687

二 文字点选的破解该如何
这边直接使用了腾讯云ocr识别(但是有误差)
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.ocr.v20181119 import ocr_client, models
try:
cred = credential.Credential("AKIDUlmX1EApENGsEI5bqpY0B5i48wTHp78s", "UhdJipfEWXHkxua08zZtxlHXWEZicHgo")
httpProfile = HttpProfile()
httpProfile.endpoint = "ocr.tencentcloudapi.com"

clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = ocr_client.OcrClient(cred, "ap-beijing", clientProfile)

req = models.GeneralBasicOCRRequest()
params = {
"ImageUrl": "https://static.geetest.com/nerualpic/word_l1_zh_2021.01.21/abstract/42685f1aec6060cd1a09c084d6776476.jpg?challenge=3726c01d0b6fb4c85bc8004d06568f67"
}
req.from_json_string(json.dumps(params))

resp = client.GeneralBasicOCR(req)
print(resp.to_json_string())

except TencentCloudSDKException as err:
print(err)
这里只需要传入文字图片地址就好了
获取文字点选图片的方法
# strhtml = driver.execute_script("return document.documentElement.innerHTML")
# soup = BeautifulSoup(strhtml, 'lxml')
# data = soup.select('body > div.geetest_panel.geetest_wind > div.geetest_panel_box.geetest_no_logo.geetest_panelshowclick > div.geetest_panel_next > div > div > div.geetest_table_box > div.geetest_window > div > div.geetest_item_wrap > img')
# s=str(data[0])
# res = re.findall(r'src="([^"]+)"',s)
# print(res[0])

参考博文:https://www.jb51.net/article/180714.htm(详细介绍了安装腾讯云sdk)



posted on   勤杂工  阅读(264)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
 
点击右上角即可分享
微信分享提示