安装seledium遇到'geckodriver' executable needs to be in PATH.问题

Traceback (most recent call last):
  File "/Users/xinxin/PycharmProjects/click/click.py", line 5, in 
    driver = webdriver.Firefox()
  File "/Users/xinxin/click/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
    self.service.start()
  File "/Users/xinxin/click/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

试图用seledium打开百度网站,代码如下:

from selenium import webdriver
from time import sleep
import os

driver = webdriver.Firefox(executable_path='/Users/xinxin/geckodriver')
driver.maximize_window()
driver.implicitly_wait(26)
url = "https://www.baidu.com"
driver.get(url)

但是没有成功,

Message: 'geckodriver' executable needs to be in PATH. 
是报错信息。

网上有很多解决办法,现在提供一种比较简单的方法:

将原先的代码

driver = webdriver.Firefox()
更改为
driver = webdriver.Firefox(executable_path='/Users/xinxin/geckodriver')

即给方法指定geckodriver的安装路径。

此外查看方法的配置信息还可以使用如下办法:

from selenium import webdriver
print(help(webdriver.Firefox) )
这个可以直接执行。



你可能感兴趣的:(python,报错)