使用Python的Selenium-Geckoriver可执行文件需要在路径中。我对编程很陌生,一开始Python大约两个月前,我正在检查斯威加特的用Python自动化无聊的东西短信。我使用的是空闲,并且已经安装了Selenium模块和Firefox浏览器。每当我尝试运行Webriver函数时,我都会得到以下内容:from selenium import webdriver
browser = webdriver.Firefox()例外:-Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0DA1080>>Traceback
(most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:AttributeError: 'Service' object has no attribute 'process'Exception ignored in: <bound method Service.__del__
of <selenium.webdriver.firefox.service.Service object at 0x00000249C0E08128>>Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:AttributeError: 'Service' object has no attribute 'process'Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Python\Python35\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Python\Python35\lib\subprocess.py", line 1224, in _execute_child
startupinfo)FileNotFoundError: [WinError 2] The system cannot find the file specifiedDuring handling of the above exception,
another exception occurred:Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
browser = webdriver.Firefox()我想我需要为geckodriver但不知道怎么做,所以有人能告诉我怎么做吗?
3 回答
梵蒂冈之花
TA贡献1900条经验 获得超5个赞
selenium.common.exceptions.WebDriverException:消息:“geckoriver”可执行文件需要在路径中。
geckodriver
PATH
在Unix系统上,如果使用的是bash兼容的shell,则可以执行以下操作将其附加到系统的搜索路径: export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step
在Windows上,您需要更新 路径系统变量,以将完整目录路径添加到可执行的geckoriver中。手动 或 命令行 (不要忘记在系统路径中添加可执行的geckoriver后重新启动系统才能生效)..原理与Unix相同。
from selenium import webdriver browser = webdriver.Firefox()
selenium.common.exceptions.WebDriverException:消息:预期的浏览器二进制位置,但无法在默认位置找到二进制,没有提供‘moz:FirefoxOptions.二进制’功能,命令行上没有设置二进制标志
from selenium import webdriverfrom selenium.webdriver.firefox.firefox_binary import FirefoxBinarybinary = FirefoxBinary('path/to/installed firefox binary')browser = webdriver.Firefox(firefox_binary=binary)
添加回答
举报
0/150
提交
取消