我正在编写一个脚本,它将保存网页的完整内容。如果我尝试使用urllib2和bs4,它只会在登录页面的内容中写入内容,而不会导航到页面内的搜索内容。但是,如果我在搜索结果页面上执行Ctrl + S操作,则会将HTML文件保存到磁盘中,该文件在文本编辑器中打开时会包含搜索结果中的所有内容。消息:'geckodriver'可执行文件需要在PATH中,但它已经是?
我关于这个问题在这里读了几帖,我试图用在这一个步骤:
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路径变量:
我已经重新启动后设置sys路径变量。
UPDATE:
我现在正在尝试使用chromdriver,因为这似乎更直接。我从chromedriver的下载页面下载hromedriver_win32.zip上的Windows笔记本电脑II'm),设置environmetal变量路径: C:\ Python27 \ LIB \站点包\硒\ webdriver的\铬\ 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
@DL仍然收到相同的消息。我要设置 - >高级 - >环境变量 - >添加路径C:\ Python27 \ selenium \ webdriver \ firefox \ geckodriver-v0.17.0 -win64 \ geckodriver.exe和C:\ Program Files文件(x86)\ Mozilla Firefox \ firefox.exe – ShaunO
@ShaunO,没关系,但firefox二进制文件的路径在哪里?你需要搜索firefox的安装位置,并为它做一个变量:)。举个例子看看它吧https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path –
@ShaunO也看看这个人,有一个类似的问题https://github.com/mozilla/geckodriver/issues/90 –