python无法打开 firefox浏览器_python – 无法使用Selenium打开Firefox浏览器

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

File "seleniumtest.py", line 3, in

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

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")

标签:python,firefox,selenium,ubuntu-14-04

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值