首页 > 解决方案 > 如何修复 selenium 错误“错误:无法检索请求的 URL”?

问题描述

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

用过的包:

有什么我可以尝试解决这个问题的吗?

暗示

尝试获取硒驱动程序时出现错误!

标签: pythonpython-3.xselenium

解决方案


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

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


推荐阅读