2017-04-27 53 views
7

在我的Python項目,我使用斯普林特(https://splinter.readthedocs.io/en/latest/)打開瀏覽器並嘗試訪問一個網站:的Python +分裂:錯誤 - httplib.BadStatusLine:「」

from splinter import Browser 

browser = Browser('chrome') 
browser.visit('http://www.google.com') 

和瀏覽器打開,並沒有能夠訪問http://www.google.com,它得到了以下錯誤:

Traceback (most recent call last): 
    File "practice.py", line 90, in <module> 
    browser = Browser('chrome') 
    File "/Library/Python/2.7/site-packages/splinter/browser.py", line 63, in Browser 
    return driver(*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/splinter/driver/webdriver/chrome.py", line 31, in __init__ 
    self.driver = Chrome(chrome_options=options, **kwargs) 
    File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 69, in __init__ 
    desired_capabilities=desired_capabilities) 
    File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 98, in __init__ 
    self.start_session(desired_capabilities, browser_profile) 
    File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 185, in start_session 
    response = self.execute(Command.NEW_SESSION, parameters) 
    File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 247, in execute 
    response = self.command_executor.execute(driver_command, params) 
    File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/remote_connection.py", line 464, in execute 
    return self._request(command_info[0], url, body=data) 
    File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/remote_connection.py", line 488, in _request 
    resp = self._conn.getresponse() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1132, in getresponse 
    response.begin() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 453, in begin 
    version, status, reason = self._read_status() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 417, in _read_status 
    raise BadStatusLine(line) 
httplib.BadStatusLine: '' 

古怪,它的工作原理不同的Mac電腦上,但是當我把它轉移到另一臺Mac電腦,遇到的錯誤。

研究但不能確定真正的問題是什麼。我可能做錯了什麼?我該如何解決這個問題?

謝謝你提前一定會給予好評/接受的答案

+0

您是否已經驗證了Mac上的chromedriver版本電腦在哪裏失敗? – gipsy

+0

@gipsy我該怎麼做?我應該尋找什麼? –

回答

0

你所描述指向過時chromedriver症狀。進入"ChromeDriver Downloads"頁面並下載最新的驅動程序。對於目前最新的穩定版Chrome 58,您需要chromedriver 2.29。

注意檢查chromedriver版本,執行:

$ chromedriver --version 

而且,還,請確保您有最新的splinterselenium

$ pip install -U splinter selenium 
+0

欣賞您的回覆。有沒有辦法通過終端安裝最新的'chromedriver'?因爲如果我手動執行此操作,那麼設置路徑似乎存在問題。 –

+0

@JoKo還沒有嘗試過,但它看起來像[此選項](http://stackoverflow.com/a/38087347/771848)。謝謝。 – alecxe

+0

仍然有問題。我檢查了chromedriver版本,結果是2.22。試過安裝,它一直說我有chromedriver 2.22,並更新了分裂/硒建議仍然得到同樣的錯誤... –