我正在使用 Ubuntu 16.04.1 LTS。执行python -V
返回Python 2.7.12
。我正在构建一个 virtualenv,以便通过以下方式将Selenium包安装到其中:
pip install -upgrade selenium
Run Code Online (Sandbox Code Playgroud)
但是在使用以下 python 脚本进行试运行时:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')
Run Code Online (Sandbox Code Playgroud)
它导致此错误:
Traceback (most recent call last):
File "/home/myuser/bin/selenium-experiment.py", line 2, in <module>
browser = webdriver.Firefox()
File "/home/myuser/python_virtualenv/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/home/myuser/python_virtualenv/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f782c1caa50>> ignored
Run Code Online (Sandbox Code Playgroud)
由于它geckodriver
是一个可执行文件,因此我得出结论,它应该由 selenium 包的安装提供,pip
或者至少通过一些说明我下一步需要做什么的消息出错。显然不是,所以我进一步挖掘:我认为也许 Ubuntu 应该有一个提供geckodriver
可执行文件的包,所以我曾经apt-file search geckodriver
搜索过它,但没有找到任何结果。
我从哪里得到这个geckodriver
可执行文件?
Pra*_*lia 51
查找适用于您的操作系统的最新版本。
提取它,然后将 geckodriver 复制到/usr/local/bin
-- 所以如果v0.11.1
是最新版本,并且您使用的是 64 位 linux,您会这样做:
export GECKO_DRIVER_VERSION='v0.24.0'
wget https://github.com/mozilla/geckodriver/releases/download/$GECKO_DRIVER_VERSION/geckodriver-$GECKO_DRIVER_VERSION-linux64.tar.gz
tar -xvzf geckodriver-$GECKO_DRIVER_VERSION-linux64.tar.gz
rm geckodriver-$GECKO_DRIVER_VERSION-linux64.tar.gz
chmod +x geckodriver
cp geckodriver /usr/local/bin/
Run Code Online (Sandbox Code Playgroud)
现在您的试运行应该可以工作了。
kra*_*ski 12
Ubuntu 16.04+:
sudo apt-get install firefox-geckodriver
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
56323 次 |
最近记录: |