page.actions.human_click / human_type
返回: Actionspage.actions.human_click(ele) / page.actions.human_type(text)拟人化点击和输入,模拟真实用户的操作节奏。
参数说明
| 参数 | 说明 |
|---|---|
| ele | 目标元素。 |
| text | 输入文本。 |
常见坑
- 速度较慢,不适合高吞吐场景。
相关示例
高风控场景下,RuyiPage 的 Firefox + BiDi 路线天然优于 Chromium 方案。配合指纹浏览器、原生动作链和环境仿真,可有效降低被检测风险。
page.actions.human_click(ele) / page.actions.human_type(text)拟人化点击和输入,模拟真实用户的操作节奏。
| 参数 | 说明 |
|---|---|
| ele | 目标元素。 |
| text | 输入文本。 |
from ruyipage import FirefoxPage, FirefoxOptions
opts = FirefoxOptions()
# 指纹浏览器
opts.set_browser_path("/path/to/fingerprint-firefox")
opts.set_fpfile("/path/to/fingerprint.json")
# 代理
opts.set_proxy("http://user:pass@proxy:8080")
page = FirefoxPage(opts)
try:
# 环境仿真
page.emulation.set_timezone("America/New_York")
page.emulation.set_locale("en-US")
page.emulation.set_geolocation(40.7128, -74.0060)
page.get("https://target-site.com")
# 拟人化操作
search = page.ele("css:input[name=q]")
page.actions.human_click(search)
page.actions.human_type("search query")
page.wait(1)
finally:
page.quit()面向高风控站点的快速开始示例,覆盖挑战处理、输入框识别和 Cookie 提取。
源码文件:app/content/ruyipage_examples/quickstart_cloudfare.py · 仓库:quickstart_cloudfare.py
# =============================
# RuyiPage 示例注释版
# 标题: Cloudflare / Copilot 快速开始
# 说明: 面向高风控站点的快速开始示例,覆盖挑战处理、输入框识别和 Cookie 提取。
# 你会学到:
# 1. 访问高风控站点并等待页面完成首屏加载
# 2. 自动尝试处理 Cloudflare 挑战
# 3. 定位输入框并发送问题
# 4. 提取 document.cookie 与完整 Cookie 信息
# 相关 API: FirefoxOptions, FirefoxPage, page.get, page.ele, page.handle_cloudflare_challenge, page.get_cookies
# =============================
# -*- coding: utf-8 -*-
"""快速开始:访问 Copilot,自动尝试通过 Cloudflare,并打印完整 Cookie。"""
from ruyipage import FirefoxOptions, FirefoxPage, Keys
QUESTION = "你好,今天天气怎么样?"
def find_input_box(page: FirefoxPage):
for _ in range(30):
box = page.ele("css:textarea")
if not box:
box = page.ele('css:[contenteditable="true"]')
if not box:
box = page.ele("css:.input-area")
if box:
return box
page.wait(1)
return None
def print_full_cookies(page: FirefoxPage) -> None:
print("\n" + "=" * 60)
print("Cloudflare / 页面 Cookie")
print("=" * 60)
raw_cookie = page.run_js("return document.cookie") or ""
print(f"document.cookie: {raw_cookie}")
cookies = page.get_cookies(all_info=True)
print(f"Cookie 数量: {len(cookies)}")
for i, cookie in enumerate(cookies, 1):
print(f"[{i}] name={cookie.name}")
print(f" value={cookie.value}")
print(f" domain={cookie.domain}")
print(f" path={cookie.path}")
print(f" httpOnly={cookie.http_only}")
print(f" secure={cookie.secure}")
print(f" sameSite={cookie.same_site}")
print(f" expiry={cookie.expiry}")
opts = FirefoxOptions()
# 如果 Firefox 不在默认安装目录,可以取消注释并指定路径。
# opts.set_browser_path(r"D:\Firefox\firefox.exe")
# 如果你想复用登录状态、Cookie、扩展,可以取消注释并指定 userdir。
# opts.set_user_dir(r"D:\ruyipage_userdir")
page = FirefoxPage(opts)
try:
print("=" * 60)
print("copilot.microsoft.com Cloudflare 测试")
print("=" * 60)
print("\n-> 访问 https://copilot.microsoft.com/ ...")
page.get("https://copilot.microsoft.com/", wait="none")
page.wait(5)
print("-> 等待输入框...")
input_box = find_input_box(page)
if input_box:
print("-> 找到输入框,开始输入问题...")
try:
input_box.click()
page.wait(0.8)
input_box.input(QUESTION, clear=True)
page.wait(0.8)
send_btn = page.ele('css:button[aria-label*="Send"]')
if not send_btn:
send_btn = page.ele('css:button[type="submit"]')
if send_btn:
print("-> 点击发送按钮...")
send_btn.click()
else:
print("-> 按 Enter 发送...")
page.actions.press(Keys.ENTER).perform()
print("-> 已发送问题,等待 Cloudflare 触发...")
page.wait(15)
except Exception as e:
print(f"-> 发送失败: {e}")
page.wait(5)
else:
print("-> 未找到输入框,直接等待 Cloudflare...")
page.wait(5)
print("\n-> 开始自动处理 Cloudflare...")
passed = page.handle_cloudflare_challenge(timeout=120, check_interval=2)
print("\n" + "=" * 60)
if passed:
print("✅ 成功通过 Cloudflare!")
print_full_cookies(page)
else:
print("❌ 超时未通过")
print("\n[+] 保持浏览器打开 500 秒...")
page.wait(500)
finally:
page.quit()
演示如何把 Firefox 指纹浏览器、指纹文件、地理位置、语言和请求头一起接入 RuyiPage。
展示通过 fpfile 与代理配置协作,让业务脚本只保留最小代理入口。
适合 Firefox、ADS、FlowerBrowser 等已打开实例的自动探测接管场景。