繁体   English   中英

无法使用Selenium打开Firefox浏览器

[英]Unable to open Firefox browser using Selenium

当我尝试使用python脚本在Ubuntu Linux 14.04上打开firefox浏览器时收到此错误消息:

File "seleniumtest.py", line 3, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error

示例代码是:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.google.com')

已经安装了像geckodriver这样的依赖关系。

wget https://github.com/mozilla/geckodriver/releases/download/v0.13.0/geckodriver-v0.13.0-linux64.tar.gz
tar -xvzf geckodriver-v0.13.0-linux64.tar.gz
rm geckodriver-v0.13.0-linux64.tar.gz
chmod +x geckodriver
cp geckodriver /usr/local/bin/

添加“executable_path =”/ usr / local / bin / geckodriver“后,输出如下:

File "seleniumtest.py", line 3, in <module>
browser = webdriver.Firefox(executable_path="/usr/local/bin/geckodriver")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error

您应该提供已安装的geckodriver的位置:

browser = webdriver.Firefox(executable_path="/path/to/geckodriver")

有一种方法可以使用Firefox。 我们可以使用Chromium。 这些是设置步骤:

sudo apt-get --yes --force-yes install chromium-browser xvfb unzip

wget -N http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux32.zip
unzip chromedriver_linux32.zip
chmod +x chromedriver

sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

如果您使用的是Mac OS,请确保已在终端中运行此命令

chmod a+x geckodriver

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM