![](/img/trans.png)
[英]Error during WebSocket handshake: Unexpected response code: 200 with ChromeDriver and Selenium
[英]Selenium Chromedriver error code : 3221225477
在python 3中用硒启动chromedriver时,加载时一切似乎至少可以进行一秒钟,但随后会弹出此错误消息:
Traceback (most recent call last):
File "C:\...\Selenium\UsingChrome.py3", line 15, in <module>
driver = webdriver.Chrome(executable_path="chromedriverwin32.exe")
File "c:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "c:\Users\...AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "c:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service chromedriverwin32.exe unexpectedly exited. Status code was: 3221225477
我当前的代码是:
from selenium import webdriver
import time, os
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = 'chromedriver.exe'
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://python.org')
...我尝试为chromedriver位置使用绝对路径,但这仍然无济于事(chromedriver.exe文件与脚本位于同一目录中)
我在Windows 10笔记本电脑上的python 3.6.5上运行
我已经在网上搜索了大约3个小时,但是没有遇到与我得到的相同的错误状态代码。
好吧,这真的很奇怪。 Chromedriver selenium在交互式外壳中启动时效果很好,但在执行脚本时效果不佳。 在我的机器上,我设置了一些批处理文件,这些批处理文件在执行python脚本时运行(运行诸如Ansicon.exe之类的命令,以便在cmd中进行彩色显示),并在使用命令'python3 script.py运行python脚本后执行'它工作得很好...所以我不确定为什么以前没有,但是无论如何,现在已经解决了。
我的代码现在是:
from selenium import webdriver
browser = webdriver.Chrome()
while 1: pass # wait forever just to let chromedriver be interactive
并且要启动的批处理文件为一行:
python3 script.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.