gpt4 book ai didi

Python/Selenium/Chromedriver : the script opens just a blank Google Chrome page

转载 作者:行者123 更新时间:2023-12-02 05:10:57 25 4
gpt4 key购买 nike

我在特定的 Windows 7 计算机上遇到浏览器自动化脚本问题。该代码是用 python 3.7.4 使用 Selenium 和 Chromedriver 编写的。当我从命令行运行它时,只有 Chrome 浏览器启动,但不会打开 URL。这个问题只出现在一台Windows 7机器上,我无法找出原因。我尝试在禁用防火墙和防病毒软件的情况下运行该脚本,但不幸的是这些措施没有帮助。命令行中也没有任何错误输出。

我认为有什么东西阻止了脚本连接到互联网,但带有 urllib.request 的 python 脚本运行没有任何问题。

该脚本在 Fedora 30 和 Debian 10 上运行良好。我还通过 Gnome Boxes 在 Windows 10 和 Windows 7 上测试了它:一切正常。

原始代码大约有 3000 行,所以这是我从头开始编写的一个小示例:

from selenium import webdriver

browser = webdriver.Chrome(executable_path = 'webdriver/chromedriver.exe')
print('Starting')
browser.get('https://google.com')

因此,当我运行脚本时,除了在 Chrome 中打开空白页面之外,什么也没有发生。并且“print”也不会执行。

我已将“浏览器”变量存储在单独的文件中。当我在同一文件中使用此变量运行脚本时,出现以下错误消息:

DevTools listening on ws://127.0.0.1:27046/devtools/browser/1ecf2c8f-c0cb-44d7-9
27d-cfa3901f645b
Traceback (most recent call last):
File "test-no-conf.py", line 5, in <module>
executable_path = 'webdriver/chromedriver.exe'
File "C:\Users\К\AppData\Local\Programs\Python\Python37\lib\site-packages\sele
nium\webdriver\chrome\webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\К\AppData\Local\Programs\Python\Python37\lib\site-packages\sele
nium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\К\AppData\Local\Programs\Python\Python37\lib\site-packages\sele
nium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\К\AppData\Local\Programs\Python\Python37\lib\site-packages\sele
nium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\К\AppData\Local\Programs\Python\Python37\lib\site-packages\sele
nium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not crea
ted
from disconnected: Unable to receive message from renderer
(Session info: chrome=77.0.3865.120)

提前谢谢您。

最佳答案

检查您机器中安装的 Chrome 浏览器版本,并将其与 Chrome 驱动程序版本进行比较。

您可以了解有关这些更改的更多信息 here并下载最新驱动程序here .

特别是这些说明:

“以下是选择要下载的 ChromeDriver 版本的步骤:首先,了解您使用的 Chrome 版本。假设您使用的是 Chrome 72.0.3626.81。

获取 Chrome 版本号,删除最后一部分,并将结果附加到 URL“https://chromedriver.storage.googleapis.com/LATEST_RELEASE_ ”。例如,对于 Chrome 版本 72.0.3626.81,您将获得 URL“https://chromedriver.storage.googleapis.com/LATEST_RELEASE_72.0.3626”。

使用上一步中创建的 URL 检索包含要使用的 ChromeDriver 版本的小文件。例如,上面的 URL 将获取包含“72.0.3626.69”的文件。 (当然,实际数字将来可能会发生变化。)

使用从上一步中检索到的版本号来构建下载 ChromeDriver 的 URL。对于版本 72.0.3626.69,URL 将为“https://chromedriver.storage.googleapis.com/index.html?path=72.0.3626.69/ ”。

初次下载后,建议您偶尔再次执行上述过程,看看是否有任何错误修复版本。”

如果这不能解决此错误,请确保关闭所有以前的 chrome 和驱动程序实例。

关于Python/Selenium/Chromedriver : the script opens just a blank Google Chrome page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58471694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com