【JS逆向】如何一招彻底解决selenium WebDriver无响应

【JS逆向】如何一招彻底解决selenium WebDriver无响应

前言

selenium 无响应,最常见的原因是,webDriver与浏览器版本不匹配导致的。

而chrome 目前新的版本都是会自动升级的,这就会导致一段时间不用selenium时,driver就无法使用了。

1、检测情况

python">from selenium import webdriver
driver = webdriver.Chrome()

#测试方法
def query_selenium():
    driver.get("https://www.baidu.***")
    print(driver.title)

if __name__ == '__main__':
    query_selenium()

如果Driver不正常的话,会一直卡着,不会有响应,或者报错

或者是报这样一个错误

The chromedriver version (114.0.5735.90) detected in PATH at E:\workspace\python\test\venv\Scripts\chromedriver.exe might not be ***patible with the detected chrome version (120.0.6099.130); currently, chromedriver 120.0.6099.109 is re***mended 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(***mand.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.***mon.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 [0x75B2F***9+25]
	RtlGetAppContainerNamedObjectPath [0x76F37C6E+286]
	RtlGetAppContainerNamedObjectPath [0x76F37C3E+238]


Process finished with exit code 1

2、重新下载新的Driver

最好的解决方案是,进入chromeDriver官方下载

访问ChromeDriver官方页面:ChromeDriver - WebDriver for Chrome - Downloads

官方展示如下:

我们查看Chrome版本可以看出,

版本号为120.0.6099.130 ,而官方出的driver 却给出的版本是 ChromeDriver 114.0.5735.90

选择 current releases 中的这个标红的链接,进入到测试版本选择里面。

选择最接近我们的 chrome版本的,能用的版本

从此处进行chromeDriver 下载

放入到python环境中去,

以下是测试结果 :

有想一起学习python爬虫的朋友,私聊

转载请说明出处内容投诉
CSS教程_站长资源网 » 【JS逆向】如何一招彻底解决selenium WebDriver无响应

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买