2017-10-19 119 views
1

尝试运行以下脚本以转至this网站,然后单击链接以导出csv。使用Python单击按钮脚本

from selenium import webdriver 
driver=webdriver.Firefox() 
driver.get("https://www.draftkings.com/contest/gamecenter/46877680") 
elem1 = driver.find_element_by_link_text("Export Lineups to CSV") 
elem1.click() 

我碰到下面的错误,并不能找到一个geckodriver。我点安装硒。我从一个较旧的视频中获得了该视频,并且我目前运行Python 3.6,因此这可能也是问题的一部分。我哪里错了?

Traceback (most recent call last): File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start stdout=self.log_file, stderr=self.log_file) File "C:\Program Files\Python36\lib\subprocess.py", line 707, in init restore_signals, start_new_session) File "C:\Program Files\Python36\lib\subprocess.py", line 992, in _execute_child startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified

在处理上述异常,另一个异常:

Traceback (most recent call last): File "C:/Users/mike/Desktop/Lineup1.py", line 2, in driver=webdriver.Firefox() File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in init self.service.start() File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

+0

当你收到一条你不明白的错误信息时,你应该做的第一件事就是Google。这通常会找到你至少可以开始的答案。 – JeffC

+0

这就是我如何堆栈溢出Jeff .. –

回答

-1

其实,硒客户端绑定尝试找到从系统路径中geckodriver可执行文件。您需要将包含可执行文件的目录添加到系统路径。 在Unix系统中,你可以做以下的,如果您使用的是bash兼容的外壳将其追加到系统的搜索路径:

export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step 

在Windows上,您将需要更新Path系统变量添加可执行geckodriver手动或命令行的完整目录路径(不要忘记在将可执行geckodriver添加到系统PATH中以使其生效后重新启动系统)。原理与Unix上的相同。

,然后尝试使用以下

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

https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

+0

我偶然发现了这个早期的Neel,谢谢你的回应。我不知道如何更新Path系统变量以手动或命令行方式将完整目录路径添加到可执行geckodriver(不要忘记在将可执行geckodriver添加到系统PATH中以使其生效后重新启动系统)。 –

+0

我去了https://github.com/mozilla/geckodriver/releases并下载了gecko.exe。在文件路径中意味着什么?我目前只是在我的桌面 –

+0

行上有lineup.py脚本,我知道了。它需要我每次都登录。这将是另一个令人头疼的问题,但至少会打开。另一件事是我不认为它点击我要求的链接。 –

1

下载geckodriver并拖动和geckodriver.exe文件拖放到项目根文件夹。这样,就不需要在代码中添加geckodriver路径,并再次尝试执行代码。没有错误会发生