Lee*_*Lee 7 python selenium webdriver selenium-chromedriver
我正在使用webdriver来配置路由器,但是当我运行脚本时:
from selenium import webdriver
self.driver = webdriver.Chrome()
Run Code Online (Sandbox Code Playgroud)
它打开chrome并且没有响应,然后引发异常:
铬无法到达.
我的电脑有两张网卡,当我禁用一张网卡时,效果很好.
我不知道为什么,请帮忙!
在纯粹的情况下,"chrome notachable"意味着可以启动Chrome二进制文件,但无法访问调试端口.
调试端口由参数设置: - remote-debugging-port = 12582
在我的情况下,它发生是因为沙盒的一些问题:
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>
Run Code Online (Sandbox Code Playgroud)
当我运行/ 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
Run Code Online (Sandbox Code Playgroud)
从上面的url我无法得到我将要做的修复SUID SandBox,但它可以通过Chrome arg --disable-setuid-sandbox(有时使用--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()
Run Code Online (Sandbox Code Playgroud)