首页 > 解决方案 > 网页正在使用 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)

标签: pythonseleniumselenium-webdriverwebdriverbots

解决方案


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)
    

我遇到了同样的问题。

  • 浏览器快照:

控制器_com

当我检查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.it 确实有一些东西......

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".


参考

您可以在以下位置找到一些详细的讨论:


推荐阅读