2017-06-16 121 views
1

我正在編寫一個腳本,它將保存網頁的完整內容。如果我嘗試使用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路徑變量:

enter image description here

我已經重新啓動後設置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 

回答

0

你也到Firefox的路徑手動添加到系統變量,你可能已經安裝了Firefox,而硒試圖找到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() 
+0

@DL仍然收到相同的消息。我要設置 - >高級 - >環境變量 - >添加路徑C:\ Python27 \ selenium \ webdriver \ firefox \ geckodriver-v0.17.0 -win64 \ geckodriver.exe和C:\ Program Files文件(x86)\ Mozilla Firefox \ firefox.exe – ShaunO

+0

@ShaunO,沒關係,但firefox二進制文件的路徑在哪裏?你需要搜索firefox的安裝位置,併爲它做一個變量:)。舉個例子看看它吧https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path –

+0

@ShaunO也看看這個人,有一個類似的問題https://github.com/mozilla/geckodriver/issues/90 –

相關問題