本文介绍了硒使用Python - Geckodriver可执行文件需要在PATH中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我是新手编程人员,大约两个月前从 Python 开始工作,现在正在使用Sweigart的自动化镗孔工具文本。我正在使用IDLE,并已安装硒模块和Firefox浏览器。 当我试图运行webdriver函数时,我得到这个: from selenium import webdriver browser = webdriver.Firefox() 例外: - < pre> 在< selenium.webdriver.firefox.service.Service对象的绑定方法Service .__ del__ 0x00000249C0DA1080>> Traceback(最近一次调用最后一个):文件C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py,第163行,在__del__ self.stop()文件C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py如果self.process是None: AttributeError:'Service'对象没有属性'process'在< bound方法中被忽略的异常服务.__ del__ < selenium.webdriver.firefox.service.Service object at 0x00000249C0E08128>> Traceback(最近一次调用最后一个):文件C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py,第163行,在__del__ self.stop()文件C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py如果self.process是None: AttributeError:'Service'对象没有属性'process' Traceback(最近一次调用的最后一个):文件C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py,第64行,在开始 stdout = self.log_file,stderr = self.log_file)文件C:\Python\Python35\lib\subprocess.py,第947行,在__init__ restore_signals,start_new_session)文件C: \Python\Python35\lib\subprocess.py,第1224行,在_execute_child startupinfo) FileNotFoundError:[WinError 2]系统找不到指定的文件 在处理上述异常期间,发生另一个异常: Traceback(最近一次调用最后一个):文件 < pyshell#11>,第1行,在< module> browser = webdriver.Firefox()文件C:\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py,行135,在__init__ self.service.start()文件C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service。 py,第71行,开始 os.path.basename(self.path),self.start_error_message) selenium.common.exceptions.WebDriverException:消息:'geckodriver'可执行文件需要PATH 。 我想我需要设置路径 geckodriver 但不知道如何,所以任何人都可以告诉我如何做到这一点? 解决方案 首先,您需要下载最新的可执行geckodriver从这里运行最新的Firefox使用硒 其实Selenium客户端绑定尝试找到 geckodriver 可执行文件 PATH 。您需要将包含可执行文件的目录添加到系统路径中。 在Unix系统上,您可以执行以下操作来追加如果你使用兼容bash的shell: export PATH = $ PATH:/ path / to / directory / of / executable / downloaded / in / previous / step 您需要更新路径系统变量以将完整的目录路径添加到可执行的geckodriver 或命令行 (将可执行geckodriver添加到系统PATH中后,请不要忘记重新启动系统) / strong>即可。原理和Unix上一样。 现在你可以像下面一样运行你的代码了: 来自selenium import webdriver browser = webdriver.Firefox() $ b 异常清楚地表明你已经安装了firefox的其他位置Selenium试图找到Firefox并从默认位置启动,但无法找到。您需要明确提供firefox安装的二进制位置来启动firefox,如下所示: - from selenium import webdriver from selenium .webdriver.firefox.firefox_binary import FirefoxBinary inary = FirefoxBinary('path / to / installed firefox binary') browser = webdriver.Firefox(firefox_binary = binary) I'm new to programming and started with Python about 2 months ago and am going over Sweigart's Automate the Boring Stuff with Python text. I'm using IDLE and already installed the selenium module and the Firefox browser.Whenever I tried to run the webdriver function, I get this:from selenium import webdriverbrowser = webdriver.Firefox()Exception :-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() 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.I think I need to set the path for geckodriver but not sure how, so can anyone tell me how would I do this? 解决方案 First of all you will need to download latest executable geckodriver from here to run latest firefox using seleniumActually The Selenium client bindings tries to locate the geckodriver executable from the system PATH. You will need to add the directory containing the executable to the system path.On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/stepOn Windows you will need to update the Path system variable to add the full directory path to the executable geckodriver manually or command line(don't forget to restart your system after adding executable geckodriver into system PATH to take effect). The principle is the same as on Unix.Now you can run your code same as you're doing as below :-from selenium import webdriverbrowser = webdriver.Firefox()Exception clearly states you have installed firefox some other location while Selenium is trying to find firefox and launch from default location but it couldn't find. You need to provide explicitly firefox installed binary location to launch firefox as below :-from selenium import webdriverfrom selenium.webdriver.firefox.firefox_binary import FirefoxBinarybinary = FirefoxBinary('path/to/installed firefox binary')browser = webdriver.Firefox(firefox_binary=binary) 这篇关于硒使用Python - Geckodriver可执行文件需要在PATH中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-05 04:22