【问题标题】:How to fix selenium error "ERROR: The requested URL could not be retrieved"?如何修复 selenium 错误“错误:无法检索请求的 URL”?
【发布时间】:2021-10-18 09:40:14
【问题描述】:

在 gitlab CI 的 docker 中,我正在使用 python selenium 运行一个非常短的测试代码

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
        
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--start-maximized')
driver = webdriver.Chrome(options=chrome_options)

driver.quit()

但它失败并出现错误

selenium.common.exceptions.WebDriverException: Message: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta type="copyright" content="Copyright (C) 1996-2016 The Squid Software Foundation and contributors">
<meta http-equiv="Content-Type" CONTENT="text/html; charset=utf-8">
<title>ERROR: The requested URL could not be retrieved</title>
<style type="text/css"><!-- 
 /*
 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
....

使用过的包:

  • 硒 4.0.0
  • chrome浏览器92.0.4515.107
  • chromedriver 92.0.4515.43

我可以尝试解决这个问题吗?

提示

尝试获取selenium驱动时出现错误!!

【问题讨论】:

    标签: python python-3.x selenium


    【解决方案1】:

    这意味着您无法访问目标网址(“https://www.google.com”)。检查您的网络上是否没有任何代理 (Running Selenium Webdriver with a proxy in Python) 或正在运行的 VPN。

    【讨论】:

    • 感谢您,但不幸的是,其他问题中提供的答案不起作用。我收到一个错误“指定 'socksProxy' 需要一个整数来表示 'socksVersion'”。
    • 我尝试通过“chrome_options.add_argument('--proxy-server=server:port')”设置代理,但仍然遇到同样的错误。
    • 我在尝试创建 webdriver 时也收到错误,而不是在我尝试连接到 URL 时。我更新了问题!!你的答案肯定是错误的。
    【解决方案2】:

    问题是 selenium 4.0.0 似乎有一个关于代理的错误。不要使用 selenium 4.0.0,使用 3.141.0。

    可能的相关票证:https://github.com/SeleniumHQ/selenium/issues/9925

    【讨论】:

      猜你喜欢
      • 2017-11-16
      • 2018-11-28
      • 2014-10-13
      • 1970-01-01
      • 2019-09-14
      • 2014-12-11
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多