对于那里的专家,我使用Spyder在Mac上运行以下代码(在Mac上):
>from selenium import webdriver
>from selenium.webdriver.common.keys import Keys
>driver = webdriver.Firefox()
我收到以下错误:
>Traceback (most recent call last):
>
> File "<ipython-input-4-fd567e24185f>", line 1, in <module>
> driver = webdriver.Firefox()
>
> File "/Users/liminfang/anaconda3/lib/python3.6/site->packages/selenium/webdriver/firefox/webdriver.py", line 160, in __init__
> self.service.start()
>
> File "/Users/liminfang/anaconda3/lib/python3.6/site->packages/selenium/webdriver/common/service.py", line 83, in start
> os.path.basename(self.path), self.start_error_message)
>
>WebDriverException: 'geckodriver' executable needs to be in PATH.
请注意,我已经通过执行
将“geckodriver”可执行文件添加到PATH中>export PATH=$PATH:/Users/liminfang/anaconda3/geckodriver
终端中的我重新启动了计算机,但错误仍然存在。谁知道这里发生了什么?请帮忙。谢谢!
答案 0 :(得分:2)
将geckodriver.exe
放入脚本文件夹,然后使用以下代码致电webdriver.Firefox
driver = webdriver.Firefox(firefox_binary=binary, firefox_profile=fp, executable_path='geckodriver.exe')
我已经52.0.2(64位)和Geckodriver 0.15.0-win64并且它正在工作!
答案 1 :(得分:0)
此错误消息......
WebDriverException: 'geckodriver' executable needs to be in PATH.
...表示在您PATH
变量中提到的目录中找不到 GeckoDriver 。
当您使用 ipython 时,您可以从mozilla/geckodriver下载最新的 GeckoDriver 并将其放置在系统中的任何位置。初始化新 WebDriver / WebClient 会话时,通过 executable_path传递 GeckoDriver 二进制文件的绝对路径参数如下:
from selenium import webdriver
driver = webdriver.Firefox(executable_path='/path/to/geckodriver')