我对编程很陌生,大约两个月前就开始使用Python了,我正在研究Sweigart用Python文本自动处理无聊的东西。我正在使用空闲,并且已经安装了Selenium模块和Firefox浏览器。
每当我尝试运行webdriver函数时,我都会得到以下内容:
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 specified
在处理上述异常的过程中,发生了另一个异常:
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
browser = webdriver.Firefox()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
self.service.start()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
我认为我需要为geckodriver
设置路径,但我不确定如何设置,那么我将如何做呢?
发布于 2016-10-23 23:16:01
selenium.common.exceptions.WebDriverException:消息:“geckodriver”可执行文件需要在路径中。
首先,您需要从这里下载最新的可执行geckodriver,以便使用Selenium运行最新的Firefox。
实际上,Selenium客户端绑定试图从系统geckodriver
定位PATH
可执行文件。您需要将包含可执行文件的目录添加到系统路径。
现在您可以运行代码,如下所示:-
from selenium import webdriver
browser = webdriver.Firefox()
selenium.common.exceptions.WebDriverException:消息:预期浏览器二进制位置,但无法在默认位置找到二进制文件,没有提供“moz:firefoxOptions.binary”功能,命令行上也没有设置二进制标志
在Selenium试图找到Firefox并从默认位置启动时,异常明显地表明您已经安装了Firefox的其他位置,但是它找不到它。您需要显式地提供Firefox安装的二进制位置,以启动Firefox,如下所示:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path/to/installed firefox binary')
browser = webdriver.Firefox(firefox_binary=binary)
https://github.com/mozilla/geckodriver/releases
适用于Windows:
从GitHub下载文件,解压缩文件,并将其粘贴到Python中。对我起作用了。
https://github.com/mozilla/geckodriver/releases
对我来说,我的道路是:
C:\Users\MYUSERNAME\AppData\Local\Programs\Python\Python39
发布于 2017-02-08 19:45:54
这为我解决了问题。
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
driver.get('http://inventwithpython.com')
发布于 2016-12-02 12:09:23
这个步骤在Ubuntu和Firefox 50上为我解决了这个问题。
/usr/local/bin
您不需要添加:
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/usr/bin/firefox'
browser = webdriver.Firefox(capabilities=firefox_capabilities)
https://stackoverflow.com/questions/40208051
复制相似问题