猿问

Selenium 停留在“访问 URL 之前检查浏览器”

这是最近出现的问题,我认为是三四天前开始的。它没有与我自己的系统隔离,因为我也在远程服务器(Windows 10、Windows Server)上运行该软件。它也没有与任何特定的 URL 隔离,因为我现在无法通过任何具有此检查的 URL。

标题:“请稍等...”“访问 URL 之前检查您的浏览器”。“此过程是自动的。您的浏览器很快就会重定向到您请求的内容。” “请最多等待 5 秒...”“Cloudflare 提供的 DDos 保护”“Ray ID:xxxxxxxxxxxxxxxxxx”

  • 我尝试过不同的系统(都基于Windows)

  • 我尝试过不同的驱动程序(gecko 和 chrome)

  • 我尝试过不同的网址

from selenium import webdriver
driver = webdriver.Chrome()
driver.get('wwww.etherdelta.com')

有谁知道我该如何解决这个问题;或者是时候放下可怜的老蒂米(程序)了?


互换的青春
浏览 178回答 4
4回答

扬帆大鱼

我在使用 Firefox 时也遇到了同样的问题。我通过切换到 Chrome 解决了这个问题。示例代码:from selenium import webdriverurl = "<WEBSITE>"options = webdriver.ChromeOptions()options.add_argument("--disable-blink-features=AutomationControlled")driver = webdriver.Chrome(options=options)driver.get(url)“--disable-blink-features=AutomationControlled”隐藏“navigator.webdriver”标志。请参阅Selenium webdriver:修改 navigator.webdriver 标志以防止 selenium 检测编辑您还必须更改 chromedriver 的一些默认变量。使用 perl 的示例:perl -pi -e 's/cdc_/dog_/g' /path/to/chromedriver欲了解更多详细信息,请查看原始帖子。请参阅当您将 selenium 与 chromedriver 一起使用时,网站可以检测到吗?编辑2Cloudflare 不断调整其算法,因此您可以尝试使用未检测到的 chromedriver,而不是手动更改 chromedriver。unDetected-chromedriver是一个优化的 Selenium Chromedriver 补丁,不应触发反机器人服务。它会自动下载驱动程序二进制文件并对其进行修补。这是否有效取决于网站和当前的开发状态。Cloudflare 似乎跟踪unDetected-chromedriver的开发。import undetected_chromedriver as ucurl = "<WEBSITE>"driver= uc.Chrome()driver.get(url)

婷婷同学_

在 Docker Linux 镜像上使用 headless Selenium 时,我遇到了同样的问题。我通过在调用网络驱动程序之前创建一个虚拟显示器来解决这个问题:from pyvirtualdisplay import Displaydisplay = Display(visible=0, size=(800, 800))&nbsp;&nbsp;display.start()不要忘记安装 pyvirtualdisplay 和 xvfb: pip install pyvirtualdisplay并且sudo apt-get install xvfb并且您必须删除 ChromeDriver 中的“无头”选项,这是我使用的完整代码:&nbsp; &nbsp; #Display in order to avoid CloudFare bot detection&nbsp; &nbsp; display = Display(visible=0, size=(800, 800))&nbsp;&nbsp;&nbsp; &nbsp; display.start()&nbsp;&nbsp;&nbsp; &nbsp; options = webdriver.ChromeOptions()&nbsp; &nbsp; options.add_argument('--no-sandbox')&nbsp; &nbsp; options.add_argument('start-maximized')&nbsp; &nbsp; options.add_argument('enable-automation')&nbsp; &nbsp; options.add_argument('--disable-infobars')&nbsp; &nbsp; options.add_argument('--disable-dev-shm-usage')&nbsp; &nbsp; options.add_argument('--disable-browser-side-navigation')&nbsp; &nbsp; options.add_argument("--remote-debugging-port=9222")&nbsp; &nbsp; # options.add_argument("--headless")&nbsp; &nbsp; options.add_argument('--disable-gpu')&nbsp; &nbsp; options.add_argument("--log-level=3")&nbsp; &nbsp; driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)由于它在我的本地计算机上无需无头即可正常工作,因此我认为模拟真实的显示器也可以完成这项工作。我不太明白为什么,但据我了解,CloudFare 尝试执行 JavaScript 代码以确认您不是机器人。拥有模拟网页显示有助于做到这一点。

慕桂英4014372

尝试使用 Chrome 数据文件夹from selenium import webdriverfrom webdriver_manager.chrome import ChromeDriverManagerfrom webdriver_manager.utils import ChromeType# Configure browseroptions = webdriver.ChromeOptions()options.add_argument(f"--user-data-dir=C:\\Users\\daria\\AppData\\Local\\Google\\Chrome\\User Data")options.add_argument("--disable-blink-features=AutomationControlled")chromedriver = ChromeDriverManager(chrome_type=ChromeType.GOOGLE,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log_level='0',&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print_first_line=False).install()driver = webdriver.Chrome(chromedriver,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options=options,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service_log_path=None)input ("End?")

jeck猫

这是因为浏览器使用来cloudfare保护自己免受DDOS (Distributed Denial Of Service) Attacks.&nbsp;有两种方法可以解决这个问题:使用time.sleep- 如果网页加载需要 5 秒,则只需使用time.sleep(5)。使用WebDriverWait-- 例如,button带有id“sample-btn”的 a 仅出现在该屏幕之后。那么你能做的是:from selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Bybtn = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'sample-btn'))) #Web driver waits for 10 seconds until element is visible推荐第2个。但如果第二个不适合你,那就选择第一个。希望这有帮助!
随时随地看视频慕课网APP

相关分类

Python
我要回答