老师您好, selenium 加入 chrome_options 参数 调起失败

来源:6-4 . selenium模拟登录知乎-3new

慕莱坞6627921

2019-06-10

老师您好, 我碰到一个问题, 尝试了一会没能解决, 麻烦您了,

在不加入chrome_options 能够调起chrome 并且展示页面, 加入后无法调起chrome
图片描述

环境配置

mac  10.14.5 
Python 3.7.3
Scrapy   1.6.0
selenium   3.141.0 

chrome 	75.0.3770.80
chrmoeDriver  75.0.3770.8

chromedirver 地址 /Users/baymax/Downloads/chromedriver
chrmoe 地址  /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome	

不加入参数 chrome_options, 能够正常调起chrmoe 展示内容

加入参数 chrome_options 调起失败, 提示 DeprecationWarning: use options instead of chrome_options

代码

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_option = Options()
chrome_option.add_argument("--disable-extensions")
chrome_option.add_experimental_option("debuggerAddress", "127.0.0.1:9222")

browser = webdriver.Chrome(executable_path='/Users/baymax/Downloads/chromedriver', chrome_options=chrome_option)
browser.get('https://www.zhihu.com/signin')

图片描述

将chrome_options 换成 options 后, chrome 没有被调起, 等待一段时间后 控制台报错, 进程中存在 chrmoedirver
图片描述

之后尝试端口换成 10187 等等 一样的错误, 已确定端口未被使用

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:9222
from chrome not reachable

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:10187
from chrome not reachable

其中在命令行中 执行可以调起chrome 并且访问到json内容

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

图片描述

麻烦老师 大家帮我下 , 卡在这里了

写回答

1回答

慕莱坞6627921

提问者

2019-06-10

看到其他同学问题中有答案,   cmd 下要启动 不能关闭

0
3
bobby
回复
慕莱坞6627921
非常感谢支持!
2019-06-11
共3条回复

Scrapy打造搜索引擎 畅销4年的Python分布式爬虫课

带你彻底掌握Scrapy,用Django+Elasticsearch搭建搜索引擎

5831 学习 · 6293 问题

查看课程