#39;selenium.common.exceptions.WebDriverException: Message: u#39;chrome not reachable(selenium.common.exceptions.WebDriverException:消息:uchrome 无法访问)
问题描述
我正在使用 webdriver 来配置路由器,但是当我运行脚本时:
I'm using webdriver to config a router, but when I run script:
from selenium import webdriver
self.driver = webdriver.Chrome()
打开chrome没有反应,然后引发异常:
It opens chrome and no response, and then raise exception:
chrome 无法访问.
chrome not reachable.
我的电脑有两张网卡,当我禁止一个时,它工作得很好.
我不知道为什么,请帮忙!
My computer has two network cards, when I forbbiden one, it works well.
I don't konw why, please help!
推荐答案
纯情况下chrome not reachable"表示Chrome二进制可以启动但调试端口不可达.
In pure case "chrome not reachable" means that Chrome binary can be started but debugging port is not reachable.
调试端口由参数设置:--remote-debugging-port=12582
Debugging port is set by argument: --remote-debugging-port=12582
就我而言,这是因为沙盒的一些问题:
In my case it happens because some issues with sand-box:
ps afvvx | grep chrome
/opt/google/chrome/chrome --disable-background-networking --disable-client-side-phishing
21026 pts/2 S+ 0:00 0 47 6008 100 0.0 | \_ cat
21027 pts/2 S+ 0:00 0 47 6008 100 0.0 | \_ cat
21029 pts/2 Z+ 0:00 0 0 0 0 0.0 | \_ [chrome-sandbox] <defunct>
当我运行/opt/google/chrome/chrome-sandbox
When I run /opt/google/chrome/chrome-sandbox
# /opt/google/chrome/chrome-sandbox -h
The setuid sandbox provides API version 1, but you need 0
Please read [https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment][1].
close: Bad file descriptor
Read on socketpair: Success
从上面的 url 我无法得到修复 SUID SandBox 的方法,但可以通过 Chrome arg --disable-setuid-sandbox(有时使用 --no-sandbox)将其关闭:
From url above I can't get what I'll to do to fix SUID SandBox, but it can be switched off by Chrome arg --disable-setuid-sandbox(sometimes with --no-sandbox):
import time
from selenium import webdriver
from xvfbwrapper import Xvfb
vdisplay = Xvfb()
vdisplay.start()
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-setuid-sandbox")
driver = webdriver.Chrome('/usr/local/sbin/chromedriver', chrome_options=chrome_options) # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
vdisplay.stop()
这篇关于'selenium.common.exceptions.WebDriverException:消息:u'chrome 无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:'selenium.common.exceptions.WebDriverException:消息:u'chrome 无法访问
基础教程推荐
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01