消息:'geckodriver' 可执行文件需要在 PATH 中,但它已经在了?
Message: 'geckodriver' executable needs to be in PATH, but it already is?
我正在编写一个脚本来保存网页的完整内容。如果我尝试使用 urllib2 和 bs4,它只会在导航到页面内的搜索后写入登录页面的内容和内容的 none。但是,如果我在搜索结果页面上按 ctrl + s,一个 html 文件将保存到磁盘,当在文本编辑器中打开该文件时,它包含搜索结果中的所有内容。
我在这里阅读了几篇关于该主题的帖子,并且正在尝试使用这一篇中的步骤:
How to save "complete webpage" not just basic html using Python
但是,在安装 geckodriver 并设置 sys 路径变量后,我继续遇到错误。这是我的有限代码:
from selenium import webdriver
>>> from selenium.webdriver.common.action_chains import ActionChains
>>> from selenium.webdriver.common.keys import Keys
>>> br = webdriver.Firefox()
这里是错误:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
这里是我设置 sys 路径变量的地方:
我在设置系统路径变量后重新启动。
更新:
我现在正在尝试使用 chromdriver,因为这看起来更直接。我从 chromedriver 的下载页面下载了 hromedriver_win32.zip II'm on a windows laptop),将环境变量路径设置为:
C:\Python27\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe
但出现类似以下错误:
>>> br = webdriver.Chrome()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
你还需要手动将Firefox的路径添加到系统变量中,
您可能已经在其他位置安装了 firefox,而 Selenium 正在尝试查找 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)
browser = webdriver.Firefox()
我正在编写一个脚本来保存网页的完整内容。如果我尝试使用 urllib2 和 bs4,它只会在导航到页面内的搜索后写入登录页面的内容和内容的 none。但是,如果我在搜索结果页面上按 ctrl + s,一个 html 文件将保存到磁盘,当在文本编辑器中打开该文件时,它包含搜索结果中的所有内容。
我在这里阅读了几篇关于该主题的帖子,并且正在尝试使用这一篇中的步骤:
How to save "complete webpage" not just basic html using Python
但是,在安装 geckodriver 并设置 sys 路径变量后,我继续遇到错误。这是我的有限代码:
from selenium import webdriver
>>> from selenium.webdriver.common.action_chains import ActionChains
>>> from selenium.webdriver.common.keys import Keys
>>> br = webdriver.Firefox()
这里是错误:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
这里是我设置 sys 路径变量的地方:
我在设置系统路径变量后重新启动。
更新:
我现在正在尝试使用 chromdriver,因为这看起来更直接。我从 chromedriver 的下载页面下载了 hromedriver_win32.zip II'm on a windows laptop),将环境变量路径设置为: C:\Python27\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe
但出现类似以下错误:
>>> br = webdriver.Chrome()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
你还需要手动将Firefox的路径添加到系统变量中, 您可能已经在其他位置安装了 firefox,而 Selenium 正在尝试查找 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)
browser = webdriver.Firefox()