繁体   English   中英

Python/Selenium/Chromedriver:脚本只打开一个空白的 Google Chrome 页面

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

我在特定 windows 7 机器上的浏览器自动化脚本有问题。 代码用 python 3.7.4 编写,带有 Selenium 和 Chromedriver。 当我从命令行运行它时,只有 Chrome 浏览器会启动,但它不会打开 url。 此问题仅发生在一台 windows 7 机器上,我无法弄清楚其原因。 我尝试在禁用防火墙和防病毒软件的情况下运行脚本,但不幸的是,这些措施无济于事。 命令行中也没有任何错误 output 。

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

该脚本在 Fedora 30 和 Debian 10 上运行良好。我还在 windows 10 和 windows 7 上进行了测试。

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

from selenium import webdriver

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

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

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

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 驱动程序版本进行比较。

您可以在此处了解有关这些更改的更多信息,并 此处下载最新的驱动程序。

特别是这些说明:

“这里是select ChromeDriver版本下载的步骤:首先,找出你正在使用的Chrome版本。假设你有Chrome 72.0.3626.81。

取Chrome版本号,去掉最后一部分,append结果到URL" https://chromedriver.storage.googleapis.com 例如,对于 Chrome 版本 72.0.3626.81,您将获得 URL“ https://chromedriver.storage.googleapis.com/LATEST_RELEASE_72.0.3626 ”。

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

使用从上一步中检索到的版本号来构建 URL 以下载 ChromeDriver。 With version 72.0.3626.69, the URL would be " https://chromedriver.storage.googleapis.com/index.html?path=72.0.3626.69/ ".

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

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

我已经重新安装了系统,现在一切正常。 那台特定机器上的系统似乎有一些问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM