can not connect to the service chromedriver问题的处理
背景
-
一个同学反馈运行如下代码
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
driver.get("https://cn.bing.com")
driver.find_element("id","sb_form_q").send_keys("松勤软件测试\n")
sleep(3)
driver.quit() -
报错了
-
一看这个错误没见到过,驱动应该是有的,版本也应该对的,无法连接到chromedriver
-
考虑到chromedriver本身就是一个web server
C:\Users\songqin008>chromedriver
Starting ChromeDriver 103.0.5060.134 (8ec6fce403b3feb0869b0732eda8bd95011d333c-refs/branch-heads/5060@{#1262}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
-
其实你是可以在浏览器中访问http://127.0.0.1:9515/的,当然这个get并不会返回太多有用的信息,只能说可以看到。
解决
-
一开始我只想到这里,但不知道如何解决
-
搜索引擎一查,说是hosts文件可能会影响
-
查了下这位同学的hosts
-
少了下面一行
127.0.0.1 localhost
-
加上后解决
-
原理暂未搞懂,是有蛛丝马迹,但没有太多依据。留作备忘
标签:ChromeDriver,service,FAQ,driver,chromedriver,sleep,connect From: https://www.cnblogs.com/wuxianfeng023/p/16644072.html