前言
selenium 無響應(yīng),最常見的原因是,webDriver與瀏覽器版本不匹配導(dǎo)致的。
而chrome 目前新的版本都是會(huì)自動(dòng)升級(jí)的,這就會(huì)導(dǎo)致一段時(shí)間不用selenium時(shí),driver就無法使用了。
1、檢測(cè)情況
from selenium import webdriver
driver = webdriver.Chrome()
#測(cè)試方法
def query_selenium():
driver.get("https://www.baidu.com")
print(driver.title)
if __name__ == '__main__':
query_selenium()
如果Driver不正常的話,會(huì)一直卡著,不會(huì)有響應(yīng),或者報(bào)錯(cuò)
或者是報(bào)這樣一個(gè)錯(cuò)誤
The chromedriver version (114.0.5735.90) detected in PATH at E:\workspace\python\test\venv\Scripts\chromedriver.exe might not be compatible with the detected chrome version (120.0.6099.130); currently, chromedriver 120.0.6099.109 is recommended for chrome 120.*, so it is advised to delete the driver in PATH and retry
Traceback (most recent call last):
File "E:\workspace\python\test\gemini\gemini_gpt.py", line 33, in <module>
driver = webdriver.Chrome()
File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
super().__init__(
File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 56, in __init__
super().__init__(
File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in __init__
self.start_session(capabilities)
File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 290, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 345, in execute
self.error_handler.check_response(response)
File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 120.0.6099.130 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe
Stacktrace:
Backtrace:
GetHandleVerifier [0x0108A813+48355]
(No symbol) [0x0101C4B1]
(No symbol) [0x00F25358]
(No symbol) [0x00F461AC]
(No symbol) [0x00F41EF3]
(No symbol) [0x00F40579]
(No symbol) [0x00F70C55]
(No symbol) [0x00F7093C]
(No symbol) [0x00F6A536]
(No symbol) [0x00F482DC]
(No symbol) [0x00F493DD]
GetHandleVerifier [0x012EAABD+2539405]
GetHandleVerifier [0x0132A78F+2800735]
GetHandleVerifier [0x0132456C+2775612]
GetHandleVerifier [0x011151E0+616112]
(No symbol) [0x01025F8C]
(No symbol) [0x01022328]
(No symbol) [0x0102240B]
(No symbol) [0x01014FF7]
BaseThreadInitThunk [0x75B2FCC9+25]
RtlGetAppContainerNamedObjectPath [0x76F37C6E+286]
RtlGetAppContainerNamedObjectPath [0x76F37C3E+238]
Process finished with exit code 1
2、重新下載新的Driver
最好的解決方案是,進(jìn)入chromeDriver官方下載
訪問ChromeDriver官方頁面:ChromeDriver - WebDriver for Chrome - Downloads
官方展示如下:
我們查看Chrome版本可以看出,
版本號(hào)為120.0.6099.130 ,而官方出的driver 卻給出的版本是?ChromeDriver 114.0.5735.90
選擇 current releases 中的這個(gè)標(biāo)紅的鏈接,進(jìn)入到測(cè)試版本選擇里面。
選擇最接近我們的 chrome版本的,能用的版本
從此處進(jìn)行chromeDriver 下載
放入到python環(huán)境中去,
以下是測(cè)試結(jié)果 :
文章來源:http://www.zghlxwxcb.cn/news/detail-789975.html
有想一起學(xué)習(xí)python爬蟲的朋友,私聊文章來源地址http://www.zghlxwxcb.cn/news/detail-789975.html
到了這里,關(guān)于【JS逆向】如何一招徹底解決selenium WebDriver無響應(yīng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!