【发布时间】:2020-07-15 03:53:06
【问题描述】:
我查看了其他几个论坛帖子并发现了类似的问题,但在尝试了所有解决方案之后,到目前为止都没有奏效。这是我的代码(直接取自我一直在关注的教程):
from time import sleep
from selenium import webdriver
driver = webdriver.Firefox(executable_path='/opt/geckoDriver/geckodriver.exe')
driver.get('https://instagram.com/')
sleep(5)
driver.close()
这是它吐出的错误:
Traceback (most recent call last):
File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Documents\Python\Instagram bot 0.py", line 5, in <module>
driver = webdriver.Firefox(executable_path='/opt/geckoDriver/geckodriver.exe')
File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver.exe' executable needs to be in PATH.
我已经下载了 geckodriver 可执行文件,但它只是在我的下载文件夹中,因为我不知道将它放在哪里以便代码访问它。我尝试了几个地方,但运气不佳。
(总的来说,我对编程/索引有些陌生,所以请像我是一个不知道的学生一样向我解释)
【问题讨论】:
-
您应该指定 geckodriver.exe 文件在可执行文件路径中的位置,而不是使用您那里的文件。
标签: python python-3.x selenium selenium-webdriver