【问题标题】:Selenium Webdriver can't access a website (The requested URL was rejected)Selenium Webdriver 无法访问网站(请求的 URL 被拒绝)
【发布时间】:2020-11-21 13:59:50
【问题描述】:

我进行了几个小时的研究,并在 Fiverr 上询问了一群人,他们都无法解决我遇到的特定问题。

我安装了 Selenium 并尝试访问一个网站。不幸的是,该站点不允许特定请求,并且根本不加载该站点。但是,如果我尝试使用我的“普通”Chrome 浏览器访问该网站,它可以正常工作。

我尝试了几件事,例如:

  • 不同的IP
  • 删除 Cookies
  • 隐身模式
  • 添加不同的用户代理
  • 隐藏可能表明正在使用 Webdriver 的功能

没有任何帮助。

这是我收到的错误的屏幕截图:



这是我正在使用的非常简单的脚本:

# coding: utf8
from selenium import webdriver

url = 'https://registrierung.gmx.net/'

# Open ChromeDriver
driver = webdriver.Chrome();
# Open URL
driver.get(url)

如果有人对此有解决方案,我将不胜感激。 如果有人可以在这里帮助我,我也愿意给大提示。

非常感谢! 大家保持健康。

【问题讨论】:

    标签: python selenium webdriver selenium-chromedriver bots


    【解决方案1】:

    我用几个参数修改了你的代码并执行了测试。以下是观察结果:

    • 代码块:

      from selenium import webdriver
      
      options = webdriver.ChromeOptions() 
      options.add_argument("start-maximized")
      options.add_experimental_option("excludeSwitches", ["enable-automation"])
      options.add_experimental_option('useAutomationExtension', False)
      driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
      driver.get("https://registrierung.gmx.net/")
      print(driver.page_source)
      
    • 控制台输出:

      <html style="" class=" adownload applicationcache blobconstructor blob-constructor borderimage borderradius boxshadow boxsizing canvas canvastext checked classlist contenteditable no-contentsecuritypolicy no-contextmenu cors cssanimations csscalc csscolumns cssfilters cssgradients cssmask csspointerevents cssreflections cssremunit cssresize csstransforms3d csstransforms csstransitions cssvhunit cssvmaxunit cssvminunit cssvwunit dataset details deviceorientation displaytable display-table draganddrop fileinput filereader filesystem flexbox fullscreen geolocation getusermedia hashchange history hsla indexeddb inlinesvg json lastchild localstorage no-mathml mediaqueries meter multiplebgs notification objectfit object-fit opacity pagevisibility performance postmessage progressbar no-regions requestanimationframe raf rgba ruby scriptasync scriptdefer sharedworkers siblinggeneral smil no-strictmode no-stylescoped supports svg svgfilters textshadow no-time no-touchevents typedarrays userselect webaudio webgl websockets websqldatabase webworkers datalistelem video svgasimg datauri no-csshyphens"><head>
      <meta http-equiv="Pragma" content="no-cache">
      <meta http-equiv="Expires" content="-1">
      <meta http-equiv="CacheControl" content="no-cache">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <link rel="shortcut icon" href="data:;base64,iVBORw0KGgo=">
      
      <script type="text/javascript">
      (function(){
      window["bobcmn"] = "10111111111010200000005200000005200000006200000001249d50ae8200000096200000000200000002300000000300000000300000006/TSPD/300000008TSPD_10130000000cTSPD_101_DID300000005https3000000b0082f871fb6ab200097a0a5b9e04f342a8fdfa6e9e63434256f3f63e9b3885e118fdacf66cc0a382208ea9dc3b70a28002d902f95eb5ac2e5d23ffe409bb24b4c57f9cb8e1a5db4bcad517230d966c75d327f561cc49e16f4300000002TS200000000200000000";
      .
      .
      <script type="text/javascript" src="/TSPD/082f871fb6ab20009afc88ee053e87fea57bf47d9659e73d0ea3c46c77969984660358739f3d19d0?type=11"></script>
      
      <script type="text/javascript">
      (function(){
      window["blobfp"] = "01010101b00400000100e803000000000d4200623938653464333234383463633839323030356632343563393735363433343663666464633135393536643461353031366131633362353762643466626238663337210068747470733a2f2f72652e73656375726974792e66356161732e636f6d2f72652f0700545350445f3734";window["slobfp"] = "08c3194e510b10009a08af8b7ee6860a22b5726420e697e4";
      
      
      })();
      
      </script>
      
      <script type="text/javascript" src="/TSPD/082f871fb6ab20009afc88ee053e87fea57bf47d9659e73d0ea3c46c77969984660358739f3d19d0?type=12"></script>
      <noscript>Please enable JavaScript to view the page content.<br/>Your support ID is: 11993951574422772310.</noscript>
      </head><body>
      <style>canvas {display:none;}</style><canvas width="800" height="600"></canvas></body></html>
      
    • 浏览器快照:


    结论

    页面来源很明显,Selenium 驱动 ChromeDriver 发起 浏览上下文被检测到并且导航被阻止。

    我本可以更深入地挖掘并提供更多见解,但令人惊讶的是,现在即使手动我也无法访问 webpage。可能我的 IP 现在被列入黑名单。一旦我的 IP 被列入白名单,我将提供更多详细信息。


    参考

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

    【讨论】:

    • 一定会的!您帮助我缩小了请求错误的范围,这很有帮助。您是否有机会知道是否有可能绕过它并“隐藏”特定的浏览上下文以便通过 Webdriver 正常访问网站,或者这不可能?
    • 正如我已经提到的,我的 IP 似乎被阻止了,所以我无法继续,我现在不想冒险通过后门将我的 IP 列入白名单。请仔细阅读参考讨论,这将提供更多类似的见解。
    • 会的 :) 再次感谢
    • @nonskill 很高兴能为您提供帮助。 Vote up questions and answers 您发现这对未来读者的利益很有帮助。见Why is voting important
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2017-06-18
    • 2021-01-06
    • 2015-09-25
    相关资源
    最近更新 更多