ChromeDriverManager().install()超时无响应问题排查求助
问题解决:ChromeDriverManager下载超时及替代方案
ChromeDriverManager的默认连接地址
ChromeDriverManager默认从以下地址获取ChromeDriver:
- 新版ChromeDriver:
https://storage.googleapis.com/chrome-for-testing-public/ - 旧版ChromeDriver:
https://chromedriver.storage.googleapis.com/
Firefox的GeckoDriverManager则从GitHub的mozilla/geckodriver发布页面获取。
解决办法
手动下载驱动并指定本地路径
直接到对应驱动的官方页面下载与浏览器版本匹配的驱动文件,然后在代码中跳过自动下载,直接指定本地路径:try: # 替换为你本地驱动文件的实际路径 driver = webdriver.Chrome(service=Service("C:/your/path/to/chromedriver.exe"), options=chrome_options) except Exception as e: print(f"Error: {e}") return配置公司代理(若允许)
如果公司网络有可访问外部的代理服务器,给ChromeDriverManager添加代理配置:try: # 替换为公司代理的地址和端口 driver_path = ChromeDriverManager(proxy="http://company-proxy:8080").install() driver = webdriver.Chrome(service=Service(driver_path), options=chrome_options) except Exception as e: print(f"Error: {e}") return使用镜像源下载
部分国内镜像提供ChromeDriver的镜像服务,可修改ChromeDriverManager的下载源:from webdriver_manager.chrome import ChromeDriverManager from webdriver_manager.core.driver_cache import DriverCacheManager from webdriver_manager.core.download_manager import DownloadManager from webdriver_manager.core.http import HttpClient try: # 使用淘宝镜像作为示例 http_client = HttpClient() download_manager = DownloadManager(http_client) cache_manager = DriverCacheManager(download_manager) driver_path = ChromeDriverManager( url="https://npm.taobao.org/mirrors/chromedriver/", cache_manager=cache_manager ).install() driver = webdriver.Chrome(service=Service(driver_path), options=chrome_options) except Exception as e: print(f"Error: {e}") return确认网络限制
先在浏览器中尝试访问上述的官方下载地址,确认是否能正常打开。如果无法访问,说明IT可能封禁了这些域名或HTTPS(443)端口,需要联系IT部门确认网络策略。
内容的提问来源于stack exchange,提问作者Chi-Chuan Huang
相关产品推荐
相关产品推荐

