使用selenium时,用webdriver初始化浏览器时间过久并伴随报错 operation timed out 的处理

随笔17小时前发布 小萝卜本卜
2 0 0

我使用的系统是archlinux,在日常更新软件包时系统自动将selenium 更新到目前(2024年5月)最新的版本,即:python-selenium 4.20.0-1。在运行我的爬虫时报错缺少依赖包,经过一番查询得知现在的驱动由webdriver_manger统一接管了。webdriver manger来对浏览器驱动和浏览器版本进行管理,但aur中的浏览器在打包时会将对应的浏览器驱动一同发布,所以我目前未存在版本不兼容的情况。

安装后未报错,但程序一直卡着那里,等了很久浏览器才启动。经过一番查询,是因为selenium会向官网检查浏览器版本和驱动版本信息,但我的网络无法访问境外(国外)网站,导致一直请求超时。

使用selenium时,用webdriver初始化浏览器时间过久并伴随报错 operation timed out 的处理使用selenium时,用webdriver初始化浏览器时间过久并伴随报错 operation timed out 的处理

driver = webdriver.Chrome()
----
Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json): operation timed out
Error sending stats to Plausible: error sending request for url (https://plausible.io/api/event): operation timed out

报错信息

大多文章都是推荐降级版本,而我是编写/etc/host将它官网的域名指向127.0.0.255后情况得到缓解,因为它不再能够访问境外服务器,而是本机地址。当然,这样的操作也不是很优雅,这将会导致selenium无法自动更新和管理浏览器驱动和版本。

?

/etc/hosts
-----
127.0.0.255 googlechromelabs.github.io

 如上所述,我的浏览器和驱动版本是自动管理的,如何您使用的我的方法,可能需要手动管理您的浏览器和驱动版本。

 

参考

selenium驱动管理器使用[https://blog.csdn.net/bugpz/article/details/127955152]
webdriiver-manger for python下载[https://pypi.org/project/webdriver-manager/]
webdriver官网[https://www.selenium.dev/zh-cn/documentation/webdriver/]
解决Selenium中的异常问题[https://www.cnblogs.com/hogwarts/p/17901106.html]

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...