我尝试使用selenium来处理一些使用JavaScript代码的网站。首先,我使用下面的简单示例
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.yahoo.com')
browser.quit()
但这根本不管用。错误消息如下所示。我想我可能错过了硒元素或其他元素。你能给我拿点光吗?
^{pr2}$我检查了"geckodriver.log"
,它显示了以下错误消息:
1479623778556 geckodriver INFO Listening on 127.0.0.1:49723
1479623778625 mozprofile::profile INFO Using profile path /tmp/rust_mozprofile.WMDGNONHQTud
1479623778628 geckodriver::marionette INFO Starting browser /usr/bin/firefox
1479623778641 geckodriver::marionette INFO Connecting to Marionette on localhost:35691
No protocol specified
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0
随着Selenium 3.0的发布,Firefox Selenium驱动程序已经更新为一个名为Marionette或“geckodriver”的新驱动程序。这是系统上的一个单独的二进制文件。在
了解如何将geckodriver与Python一起使用:Selenium install Marionette webdriver
如果要使用旧的Selenium驱动程序,版本2.x:
Install your Python packages properly using virtual environment
pip install "selenium<3"
将Firefox降级到45版本,或将
firefox
version 45二进制文件添加到您的“PATH”环境变量中现在Firefox在Selenium web驱动程序方面做得不太好,我建议您改用Chrome驱动程序
Pl检查路径或者如果您在Linux上,请查看http://www.linuxquestions.org/questions/linux-server-73/can't-open-display-no-protocol-specified-using-gdm-4175462031/
相关问题 更多 >
编程相关推荐