Cloudflare 如何区分 Selenium 和 Requests 流量?

ku8*_*8zi 10 python selenium web-crawler cloudflare python-requests

语境

我目前正在尝试使用 Python 中的 Selenium 和 Requests 模块构建一个小型机器人。
但是,我想与之交互的网页在 Cloudflare 后面运行。
我的 python 脚本使用 stem 模块在 Tor 上运行。
我的流量分析基于使用 Persist Logs 的 Firefox 的“开发者选项->网络”。

到目前为止我的发现:

  • Selenium 的 Firefox webdriver 经常可以访问网页,而无需经过“检查浏览器页面”(返回码 503)和“验证码页面”(返回码 403)。
  • 使用相同的用户代理请求会话对象总是导致“验证码页面”(返回代码 403)。

如果 Cloudflare 正在检查我的 Javascript 功能,我的请求模块不应该返回 503 吗?

代码示例

driver = webdriver.Firefox(firefox_profile=fp, options=fOptions)
driver.get("https://www.cloudflare.com")   # usually returns code 200 without verifying the browser

session = requests.Session()
# ... applied socks5 proxy for both http and https ... #
session.headers.update({"user-agent": driver.execute_script("return navigator.userAgent;")})
page = session.get("https://www.cloudflare.com")
print(page.status_code) # return code 403
print(page.text)        # returns "captcha page"
Run Code Online (Sandbox Code Playgroud)

Selenium 和 Requests 模块都使用相同的用户代理和 IP。
两者都使用不带任何参数的 GET。
Cloudflare 如何区分这些流量?
我错过了什么吗?


我试图将 cookie 从 webdriver 传输到请求会话,以查看是否可以绕过,但没有运气。
这是使用的代码:

for c in driver.get_cookies():
    session.cookies.set(c['name'], c['value'], domain=c['domain'])
Run Code Online (Sandbox Code Playgroud)

Ash*_*mar 0

验证码响应取决于浏览器指纹。这不仅仅是发送 Cookie 和用户代理。

从开发者控制台的“网络”选项卡复制所有标头,并将所有键值对作为请求库中的标头发送。

这个方法应该在逻辑上有效。