【发布时间】:2020-03-23 00:29:00
【问题描述】:
我在特定 Windows 7 机器上的浏览器自动化脚本有问题。代码是用 Selenium 和 Chromedriver 用 python 3.7.4 编写的。当我从命令行运行它时,只有 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 中打开一个空白页面外,什么也没有发生。并且“打印”也没有执行。
我已将“浏览器”变量存储在单独的文件中。当我在同一个文件中使用此变量运行脚本时,我收到以下错误消息:
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)
提前谢谢你。
【问题讨论】:
-
请分享脚本
-
请阅读minimal reproducible example并相应地编辑您的问题
-
谢谢。我在帖子中添加了一个代码示例。这不是我在那些机器上运行的实际代码。但是我写了几个小代码示例(比如那个)来测试脚本是否可以工作,但它无法获取 url。
-
在打印语句之前打开浏览器对我来说似乎很奇怪。
标签: python selenium selenium-chromedriver