1. 程式人生 > >Selenium啟動Chrome瀏覽器提示“請停用以開發者模式執行的擴充套件程式”的解決辦法

Selenium啟動Chrome瀏覽器提示“請停用以開發者模式執行的擴充套件程式”的解決辦法

安裝了selenium,python執行下面程式碼:

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://www.baidu.com/') # 啟動Chrome瀏覽器開啟百度網址

報錯:

Traceback (most recent call last):
 File "I:/python/c ip/go.py", line 4, in <module>
 browser.get('http://www.baidu.com/')
 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 324, in get
 self.execute(Command.GET, {'url': url})
 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 310, in execute
 response = self.command_executor.execute(driver_command, params)
 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 466, in execute
 return self._request(command_info[0], url, body=data)
 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 490, in _request
 resp = self._conn.getresponse()
 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\http\client.py", line 1174, in getresponse
 response.begin()
 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\http\client.py", line 282, in begin
 version, status, reason = self._read_status()
 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\http\client.py", line 243, in _read_status
 line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\socket.py", line 571, in readinto
 return self._sock.recv_into(b)
 ConnectionResetError: [WinError 10054] 遠端主機強迫關閉了一個現有的連線。

並且Chrome瀏覽器提示:請停用以開發者模式執行的擴充套件程式,網址輸入框中只顯示:data;,如下圖:

請停用以開發者模式執行的擴充套件程式

這個問題是由於因為瀏覽器驅動Chromedriver和Chrome的版本不相容導致無法通過driver在瀏覽器輸入網址而出現的,解決的辦法很簡單:檢視你Chrome瀏覽器的版本(幫助 -> 關於Google Chrome(G)),下載對應版本的瀏覽器驅動就可以了。

下載對應Chromedriver後放到python目錄下,成功執行程式,結果如下:

附表:最新的Chromedriver與Chrome的版本對應關係表:

chromedriver版本 支援的Chrome版本
v2.35 v62-64
v2.34 v61-63
v2.33 v60-62
v2.32 v59-61
v2.31 v58-60
v2.30 v58-60
v2.29 v56-58
v2.28 v55-57
v2.27 v54-56
v2.26 v53-55
v2.25 v53-55
v2.24 v52-54
v2.23 v51-53
v2.22 v49-52
v2.21 v46-50
v2.20 v43-48
v2.19 v43-47
v2.18 v43-46
v2.17 v42-43
v2.13 v42-45
v2.15 v40-43
v2.14 v39-42
v2.13 v38-41
v2.12 v36-40
v2.11 v36-40
v2.10 v33-36
v2.9 v31-34
v2.8 v30-33
v2.7 v30-33
v2.6 v29-32
v2.5 v29-32
v2.4 v29-32

不同版本的Chromedriver都可以通過這裡連結下載: