我正在嘗試使用selenium包連接到web瀏覽器的基本python腳本。顯示的錯誤日誌如下所示。使用python-selenium包時出錯
Traceback (most recent call last):
File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
在處理上述異常,另一個異常:
Traceback (most recent call last):
File "F:/WinPython/WinPython-64bit-3.5.2.3Qt5/python-3.5.2.amd64/py_codes/python_org_search.py", line 4, in <module>
driver = webdriver.Firefox()
File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__
self.service.start()
File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\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.
異常日誌不足以理解問題。也顯示你的代碼 – Andersson
重複http://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path已經有了答案 – CJC
@Andersson這裏是代碼from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get(「http://www.python.org」) 在driver.title中斷言「Python」 ELEM = driver.find_element_by_name( 「q」) elem.clear() elem.send_keys( 「PYCON」) elem.send_keys(Keys.RETURN) 斷言 「未找到結果」。不在driver.page_source driver.close() – Anjishnu