Today, if I want to use Python to implement a script that automatically refreshes web pages, I need to use selenium.
Because the chromedriver was not specified at the beginning, an error was reported:
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\common
\service.py", line 76, in start
stdin=PIPE)
File "D:\Anaconda3\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "D:\Anaconda3\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "f5.py", line 5, in <module>
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\chrome
\webdriver.py", line 68, in __init__
self.service.start()
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\common
\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver'
executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
Then I went to download chromedriver, downloaded a version, and the result was an error:
DevTools listening on ws://127.0.0.1:12059/devtools/browser/c21c107d-fa6a-
4739-8cd6-0f1718fb6db8
Traceback (most recent call last):
[38752:39792:0423/153855.462:ERROR:plugin_data_remover_impl.cc(123)] Timed
out
File "f5.py", line 6, in <module>
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote
\webdriver.py", line 726, in maximize_window
self.execute(command, {"windowHandle": "current"})
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote
\webdriver.py", line 310, in execute
response = self.command_executor.execute(driver_command, params)
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote
\remote_connection.py", line 466, in execute
return self._request(command_info[0], url, body=data)
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote
\remote_connection.py", line 490, in _request
resp = self._conn.getresponse()
File "D:\Anaconda3\lib\http\client.py", line 1331, in getresponse
response.begin()
File "D:\Anaconda3\lib\http\client.py", line 297, in begin
version, status, reason = self._read_status()
File "D:\Anaconda3\lib\http\client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "D:\Anaconda3\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
After continuing to search for the answer on Baidu, I found that:
when using selenium to open the chrome browser, you need to use chromedriver, and
the versions of chromedriver and chrome are also suitable for each other. The corresponding relationship is as follows:
|chromedriver version|supported chrome version
| - | :-: |
|v2.36 |v64-66
|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
So, first enter in the browser address bar: chrome://version
get the browser version, then find the corresponding chromedriver version, and download it.
The download link is: