python - 如何修复 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
....
用过的包:
- 硒 4.0.0
- 铬浏览器 92.0.4515.107
- 铬驱动程序 92.0.4515.43
有什么我可以尝试解决这个问题的吗?
暗示
尝试获取硒驱动程序时出现错误!
解决方案
问题是 selenium 4.0.0 似乎有关于代理的错误。不要使用 selenium 4.0.0,使用 3.141.0。
推荐阅读
- excel - 另一个 Excel 求解器中的 Excel 求解器(求解器的串联连接)
- excel - 句号后第一个字母大写的Excel公式
- r - 根据最高百分比将行名分配给列名
- spring - Spring Cloud Gateway API - 路由上的上下文路径不起作用
- android - FCM推送消息发送没有主题和不同的数据块
- c# - Xbox 上的 C# UWP Windows.Web.Http.HttpClient 错误 401
- android - 在 ConstraintLayout 中,当我将视图的 layoutDirection 设置为“rtl”时,出现了一些问题。如何避免这种情况?
- windows - Windows 命令 'start /max' - 'call' 的等价物是什么?
- javascript - 在 AttributeInspector (ESRI JS API 3.24) 的下拉列表中过滤值
- azure - 用于更新或插入属于多个分区键的文档的存储过程