dp自动化登陆之hCaptcha 验证码

hCaptcha 是一种常见的验证码服务,用于区分人类用户和自动化程序。由于其基于图像识别和行为分析,下面介绍如何使用自动化点击验证码完成登陆。

思路:登陆目标网站触发验证码,截图并发给打码平台返回坐标,模拟人工点击完成验证

1、注册识别 hCaptcha API,获取授权

python 复制代码
import requests
def get_rect(base64_list, title_list):
	url = "https://api.acedata.cloud/captcha/recognition/hcaptcha"
	headers = {
	    "accept": "application/json",
	    "authorization": "授权码",
	    "content-type": "application/json"
	}
	payload = {
	      "queries": base64_list,
	      "question": ",".join(title_list)
	}
	response = requests.post(url, json=payload, headers=headers).json()
	return response

2、登陆目标网站,触发网站验证码

python 复制代码
co = ChromiumOptions().headless(False).auto_port()
co.set_argument('--enable-translate')
page = ChromiumPage(co)
co.incognito()
page.get('https://www.ebay.com/sh/ord/?filter=status%3AALL_ORDERS%2Ctimerange%3APREVIOUSMONTH')
if page.title != "Security Measure":
    login(page, username_str, password_str)

3、将验证码截图获取图片并转为base64编码

python 复制代码
def land():
	page.get_screenshot(path='tmp', name='pic.jpg', full_page=True)
	rangle = (74, 10, 474, 610)  # 左、上、右、下
	img = Image.open(r'tmp/pic.jpg')
	cropped_img = img.crop(rangle)
	# 保存裁剪后的图片
	cropped_img.save(r'tmp/cropped_image.png')
	title = (79, 15, 464, 130)
	img.crop(title).save(r"tmp/title.png")
	reader = easyocr.Reader(['ch_sim', 'en'])
    result = reader.readtext(img)
    title_list = []
    for detection in result:
        print(detection[1])
        title_list.append(detection[1])
	img1 = (79, 135, 209, 260)
	img.crop(img1).save(r"tmp/img1.png")
	img2 = (209, 135, 339, 260)
	img.crop(img2).save(r"tmp/img2.png")
	img3 = (339, 135, 469,260)
	img.crop(img3).save(r"tmp/img3.png")
	img4 = (79, 265, 209, 395)
	img.crop(img4).save(r"tmp/img4.png")
	img5 = (209, 265, 339, 395)
	img.crop(img5).save(r"tmp/img5.png")
	img6 = (339, 265, 469, 395)
	img.crop(img6).save(r"tmp/img6.png")
	img7 = (79, 395, 209, 525)
	img.crop(img7).save(r"tmp/img7.png")
	img8 = (209, 395, 339, 525)
	img.crop(img8).save(r"tmp/img8.png")
	img9 = (339, 395, 469, 525)
	img.crop(img9).save(r"tmp/img9.png")
	base64_list = []
	for i in range(1, 10):
	    with  open(f'tmp/img{i}.png', "rb") as img_file:
	        encoded_string = base64.b64encode(img_file.read()).decode('utf-8')
	        base64_list.append(encoded_string)
	return base64_list,title_list

4、将图片列表和标题传入图片识别api返回目标坐标,模拟完成点击

python 复制代码
res = get_rect(base64_list, 'tmp/title.png')
objects = res["solution"]["objects"]
img_list = [img1, img2, img3, img4, img5, img6, img7, img8, img9]
print("1111", objects)
for i in range(9):
    if objects[i]:
        target = ((int(img_list[i][0]) + int(img_list[i][2])) / 2, (int(img_list[i][1]) + int(img_list[i][3])) / 2)
        page.actions.move_to(target).click()
        time.sleep(1)
相关推荐
孟健14 小时前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞16 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽18 小时前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程1 天前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪1 天前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook1 天前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田1 天前
使用 pkgutil 实现动态插件系统
python
前端付豪2 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽2 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战2 天前
Pydantic配置管理最佳实践(一)
python