python+selenium firefox 驱动

环境:Python3.5 + win10(64bits)+Firefox 52.0.1 (32 位)

安装selenium运行sample

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://www.baidu.com/')


报错:

H:\Python\Python35\python.exe H:/Python/PycharmProjects/helloworld/SeleniumDemo1.py
Traceback (most recent call last):
  File "H:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "H:\Python\Python35\lib\subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "H:\Python\Python35\lib\subprocess.py", line 1220, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "H:/Python/PycharmProjects/helloworld/SeleniumDemo1.py", line 27, in <module>
    browser = webdriver.Firefox()
  File "H:\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in __init__
    self.service.start()
  File "H:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

解决:(摘自stackoverflow的用户zzy)

First we know that gekodriver is the driver engine of Firefox,and we know thatdriver.Firefox() is used to open Firefox browser, and it will call the gekodriver engine ,so we need to give the gekodirver a executable permission.so we download the latest gekodriver uncompress the tar packge ,and put gekodriver at the/usr/bin/ok,that's my answer and i have tested.

需要安装firefox的驱动gekodriver,把gekodriver.exe文件添加到Python的安装目录(即环境变量path里配置的位置,我的是H:\Python\Python35)

在运行sample

最后运行成功,打开百度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值