我目前正在閱讀使用Python自動化煩人的東西,並試圖學習如何使用硒。目前,我只是試圖打開一個網頁,甚至無法讓它工作。我知道有更簡單的方法來使用python啓動網頁,但我的目標是稍後使用網頁內容,所以這就是我使用硒的原因。使用硒啓動Firefox的網頁
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.python.org")
當我運行這段代碼,但它成功地啓動Firefox,但它不打開網頁我指定。這個錯誤也被返回。
Traceback (most recent call last):
File "/Users/lbor/Desktop/se.py", line 2, in <module>
driver = webdriver.Firefox()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__
self.binary, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 108, in _wait_until_connectable
% (self.profile.path))
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /var/folders/4c/gsw7v5b118j406zxj3lxctt40000gn/T/tmp_dgwff4s If you specified a log_file in the FirefoxBinary constructor, check it for details.
我不明白這個問題是什麼或如何去解決它。我運行OS 10.12.5,Python 3.6,Selenium 2.53.6,Firefox 53.0.3。至於geckodriver,我不知道那是什麼或如何安裝它。
我只是試過這個,但它仍然只是啓動Firefox,但不是慾望網頁 – Lmorj
請看我最近的編輯。 – Ajax1234
非常感謝您的幫助Ajax,我知道我是一個noob,但你的解釋確實有幫助。我解決了它。 – Lmorj