网页正在使用 Chromedriver 作为机器人检测 Selenium Webdriver

新手上路,请多包涵

我正在尝试使用 python 抓取 https://www.controller.com/ ,并且由于该页面检测到使用 pandas.get_html 的机器人,并且请求使用用户代理和旋转代理,我求助于使用 selenium网络驱动程序。但是,这也被检测为带有以下消息的机器人。谁能解释我怎样才能克服这个问题?:

请原谅我们的打扰…当您浏览 www.controller.com 时,关于您浏览器的一些事情让我们认为您是一个机器人。发生这种情况的原因可能有几个: 您是超级用户,以超人的速度浏览该网站。您已在网络浏览器中禁用 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)

原文由 Alex 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 771
2 个回答

您提到了 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 时,发现该网站引用了 --- window.onbeforeunload 上的 distil_referrer,如下所示:

 <script type="text/javascript" id="">
    window.onbeforeunload=function(a){"undefined"!==typeof sessionStorage&&sessionStorage.removeItem("distil_referrer")};
</script>

快照:

卸载前

这清楚地表明该网站受到 Bot Management 服务提供商 Distil Networks 的保护, ChromeDriver 的导航被检测到并随后 被阻止


蒸馏

根据文章 There Really Is Something About Distil.it…

Distil 通过观察站点行为和识别抓取程序特有的模式来保护站点免受自动内容抓取机器人的侵害。当 Distil 在一个站点上识别出恶意机器人时,它会创建一个列入黑名单的行为配置文件,并将其部署到其所有客户。类似于机器人防火墙,Distil 检测模式并做出反应。

进一步,

"One pattern with Selenium was automating the theft of Web content" ,Distil CEO 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".


参考

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

原文由 undetected Selenium 发布,翻译遵循 CC BY-SA 4.0 许可协议

终于解决了问题,无头模式也能正常工作。

 chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--headless")

driver = webdriver.Chrome("chromedriver.exe", options=chrome_options)

driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.53 Safari/537.36'})
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")

原文由 Raphael 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题