python - 网页正在使用 Chromedriver 作为机器人检测 Selenium Webdriver
问题描述
我正在尝试使用 python 抓取https://www.controller.com/,并且由于页面检测到使用 bot 的机器人pandas.get_html
,并且使用用户代理和旋转代理进行请求,因此我使用了 selenium webdriver。但是,这也被检测为带有以下消息的机器人。任何人都可以解释我怎样才能克服这个问题?:
请原谅我们的打扰……当您浏览 www.controller.com 时,您的浏览器的某些内容让我们认为您是机器人。有几个原因可能会发生这种情况:您是一个超级用户,以超人的速度浏览该网站。您已在 Web 浏览器中禁用 JavaScript。第三方浏览器插件(例如 Ghostery 或 NoScript)正在阻止 JavaScript 运行。此支持文章中提供了其他信息。要申请解除封锁,请填写下面的表格,我们会尽快审核”
这是我的代码:
from selenium import webdriver
import requests
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
#options.add_argument('headless')
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://www.controller.com/')
driver.implicitly_wait(30)
解决方案
pandas.get_html
你只在你的问题中提到过,而且options.add_argument('headless')
只在你的代码中提到过,所以不确定你是否正在实现它们。但是,从您的代码尝试中取出最少代码如下:
代码块:
from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_argument("disable-infobars") options.add_argument("--disable-extensions") driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe') driver.get('https://www.controller.com/') print(driver.title)
我遇到了同样的问题。
- 浏览器快照:
当我检查HTML DOM时,观察到网站引用distil_referrer如下window.onbeforeunload
:
<script type="text/javascript" id="">
window.onbeforeunload=function(a){"undefined"!==typeof sessionStorage&&sessionStorage.removeItem("distil_referrer")};
</script>
快照:
这清楚地表明该网站受到Bot Management服务提供商Distil Networks的保护,并且ChromeDriver的导航被检测到并随后被阻止。
蒸馏
Distil 通过观察网站行为和识别抓取工具特有的模式来保护网站免受自动内容抓取机器人的侵害。当 Distil 在一个站点上识别出恶意机器人时,它会创建一个列入黑名单的行为配置文件,并部署到其所有客户。类似于机器人防火墙的东西,Distil 检测模式并做出反应。
更远,
"One pattern with Selenium was automating the theft of Web content"
,Distil 首席执行官 Rami Essaid 在上周接受采访时表示。"Even though they can create new bots, we figured out a way to identify Selenium the a tool they're using, so we're blocking Selenium no matter how many times they iterate on that bot. We're doing that now with Python and a lot of different technologies. Once we see a pattern emerge from one type of bot, then we work to reverse engineer the technology they use and identify it as malicious".
参考
您可以在以下位置找到一些详细的讨论:
推荐阅读
- python - 如何在使用带有请求库的 POST 方法时修复 406 状态代码
- python - python返回xmlblock并删除编码标签
- java - 检查字符串是否存在于 HashSet Java 中的时间复杂度
- r - 创建每个采样站点的唯一访问列
- android - 使用 Gradle 7.1.0-alpha03 和 Composer 的新 Android 项目无法构建
- excel - Excel - 格式化一个单元格,使其显示另一个单元格的算术表达式
- python - 在 Windows Python 中处理权限被拒绝错误
- xcode13 - XCode 13 beta 2,iOS 15 上的应用安装失败
- python-3.x - 使用 Python 多处理并行加载大型数据集
- c - 如何在编译旧 MUD 时修复 collect2 错误?