如果您对在Ubuntu服务器上无头运行Chromedriver感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于在Ubuntu服务器上无头运行Chromedriver的详细内容
如果您对在Ubuntu服务器上无头运行Chromedriver感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于在Ubuntu服务器上无头运行Chromedriver的详细内容,我们还将为您解答ubuntu终端启动chrome的相关问题,并且为您提供关于centos 无界面 服务器 安装chrome部署chromedriver、Chromedriver 在无头模式下运行不能加载插件、chromedriver:ubuntu 14.04 64位上缺少各种lib依赖项、Docker ubuntu 安装 chrome chromedriver的有价值信息。
本文目录一览:- 在Ubuntu服务器上无头运行Chromedriver(ubuntu终端启动chrome)
- centos 无界面 服务器 安装chrome部署chromedriver
- Chromedriver 在无头模式下运行不能加载插件
- chromedriver:ubuntu 14.04 64位上缺少各种lib依赖项
- Docker ubuntu 安装 chrome chromedriver
在Ubuntu服务器上无头运行Chromedriver(ubuntu终端启动chrome)
我将Selenium与Java(1.8)中的Chromedriver结合使用来进行一些自动的网络爬网:
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");WebDriver driver = new ChromeDriver();driver.get("someurl.com");
我正在尝试迁移到Ubuntu 16.04服务器。在服务器上,我安装了Ubuntu
chromedriver版本2.37,chrome版本65。根据chromedriver文档,这些版本兼容。我已经更改了指定chromedriver在Ubuntu中的位置的代码:
System.setProperty("webdriver.chrome.driver", "/usr/lib/local/chromedriver");
在运行程序之前,我先启动xvfb:
Xvfb -ac :99 -screen 0 1280x1024x16 &export DISPLAY=:99
然后执行我的程序:
java -jar myprogram.jar
将以下内容打印到控制台:
Starting ChromeDriver 2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7) on port 10574Only local connections are allowed.Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.4.0-112-generic x86_64) (WARNING: The server did not provide any stacktrace information)Command duration or timeout: 60.35 secondsBuild info: version: ''3.11.0'', revision: ''e59cfb3'', time: ''2018-03-11T20:33:15.31Z''System info: host: ''ubuntu-s-1vcpu-1gb-nyc1-01'', ip: ''127.0.1.1'', os.name: ''Linux'', os.arch: ''amd64'', os.version: ''4.4.0-112-generic'', java.version: ''1.8.0_151''Driver info: driver.version: ChromeDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166) at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53) at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91) at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958) at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126) at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:132) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123) at RHio.Test.main(Test.java:39)
答案1
小编典典该错误确实使我们对发生的错误有所了解:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
在尝试 无头* 启动 Ubuntu Server 上的 Chromedriver 和 Chrome时 ,您必须通过几个 选项
,如下所示: __*__
from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsoptions = Options()options.add_argument("--headless")options.add_argument("--no-sandbox")options.add_argument("start-maximized")options.add_argument("disable-infobars")options.add_argument("--disable-extensions")driver = webdriver.Chrome(chrome_options=options, executable_path=''/path/to/chromedriver'')driver.get(''http://google.com/'')driver.quit()
补充笔记
根据强制性要求和#1341,请确保:
- Chromedriver 在
/usr/local/bin/
- Chrome浏览器 位于
/usr/bin/google-chrome
tl; dr
sandbox
的故事
centos 无界面 服务器 安装chrome部署chromedriver
转:https://blog.csdn.net/u013849486/article/details/79466359
基本 做完了,要弄进docker里面去了的时候,才搜到 docker-chromium 基础镜像,和前辈走过的路,也许这样更方便吧,而且生产环境 就是linux-centos所以 不如一直在Linux或者docker里开发,我一直在mac里开发,所以迈过了很多坑~
http://blog.csdn.net/littlebrain4solving/article/details/77102084可以参考吧~。。。
说在头里,的确比post 模拟,省很多事,也会慢很多,但最麻烦的,就是 都是坑,没人踩过的坑。
在弄项目过程中,大概做了2个月吧,代码量根本不多,500行python,就是卡在了无数的坑中。
最难忘的一个坑就是,我在mac开发,类Linux,结果测试放到centos生产环境,一系列崩塌~~
所以一定要有无尽崩溃的准备,再继续读下去~
一个重大坑就是 ,ssl验证,没弄太清楚,反正 Linux centos无界面访问 一个https的url失败了,返回了空白页面
类似<html><body></body></html>,stackoverflow 搜到了类似结果,但是是phantomjs的所以改用phantomjs,
可行,参考:
https://stackoverflow.com/questions/29463603/phantomjs-returning-empty-web-page-python-selenium/36159299#36159299
重点就在于
driver = webdriver.PhantomJS(service_args=[‘--ignore-ssl-errors=true‘,‘--ssl-protocol=TLSv1‘])
这个ignore 起了作用,我尽力搜索,以及尝试在chrome 里这样操作,失败了~
网上有很多经验,这里呢根据我的实际情况,算是总结,算给大家提供借鉴了。
服务器
uname -a
Linux VM_171_246_centos 3.10.0-327.36.3.el7.x86_64 #1 SMP Mon Oct 24 16:09:20 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
业务情况是 python + selenium + chromedriver
python和selenium的安装啊部署都不介绍了,网上有其他总结,新手来说也算挺多事,但也算有很多经验,就不在这里说了。
因为简单的模拟post请求,既复杂又可能无法达到预计目标,甚至仅仅作为初期项目模型的构建而临时采用,selenium的引入就要选择实际的浏览器,我推荐chrome因为没,没过别的,经力时间有限,有留言说其他的不好。
首先要安装chrome,http://blog.csdn.net/xds2ml/article/details/52982748
我是看这位朋友的弄的,只看1,2点装好就行了,而且第1点中要记得换行应该是这样的,应该是,朋友上传后被排版弄乱了。
[google]
name=Google-x86_64
baseurl=http://dl.google.com/linux/rpm/stable/x86_64
enabled=1
gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
第二点的yum update可以不弄,我是没弄,yum不太懂,朋友们可以拓展。
然后是chromedriver的部署,首先要搞清chrome和其driver的对应关系,我用的是chrome-v64和driver2.3.5
对应关系在这位朋友这,http://blog.csdn.net/cz9025/article/details/70160273。
对应下载在这,记得看清更新日期,2.9比2.3.5要旧,我写这篇博客时最新的是2.3.6。
http://npm.taobao.org/mirrors/chromedriver/
然后就是将driver放在linux某个地方 zip格式就unzip,得到运行文件就记下路径(pwd)
部署就算ok了,然后是如何无界面使用。
一般推荐是Xvfb,但是都有点旧了可能,也听说这样是可以的,所以我尝试了chrome简单的参数配置,是可以的。
关键点就是 记得给server配一个其他用户,root用户启动会失败。不知为啥,其他用户是可以的。
#from pyvirtualdisplay import display
from selenium import webdriver
#display = display(visible=0,size=(800,600))
#display.start()
chrome_opt = webdriver.ChromeOptions()
chrome_opt.add_argument(‘--headless‘)
chrome_opt.add_argument(‘--disable-gpu‘)
#chrome_opt.add_argument(‘--ignore-certificate-errors‘)
try:
a=webdriver.Chrome(chrome_options=chrome_opt,executable_path=‘/usr/bin/google-chrome/chromedriver‘)
except Exception as e:
print(e)
#display.stop()
else:
a.get("http://www.baidu.com")
print(a.title)
a.quit()
#display.stop()
python test.py
输出
Chromedriver 在无头模式下运行不能加载插件
使用 Selenium + Chromedriver 自动化测试,由于要使用私有隧道代理,发现 Chromedriver 不支持私有代理,于是使用第三方驱动 phantomJS ,但是 phantomJS 问题多好多定位不到元素问题,于是百度后发现可以使用浏览器插件的形式使用私有代理,但是在无头模式下是不行的,有哪位大佬遇到这种问题了,跪求解决思路
chromedriver:ubuntu 14.04 64位上缺少各种lib依赖项
wget http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip
在我的ubuntu 14.04上
x86_64 x86_64 x86_64 GNU/Linux
我收到以下消息
./chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
进一步挖掘我发现它缺少一大堆.
那我在哪里可以获取丢失的文件?
me@me:/var/chrome# ldd ./chromedriver linux-vdso.so.1 => (0x00007ffc0e5aa000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f472eb63000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f472e95f000) libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f472e70e000) libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f472e4wget http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip
)
wget http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip(0x00007f472ddcd000)
libnss3.so => not found
libnssutil3.so => not found
libsmime3.so => not found
libnspr4.so => not found
libgconf-2.so.4 => not found
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f472e0d1000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f472dac7000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f472d8b1000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f472d693000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f472d2ce000)
/lib64/ld-linux-x86-64.so.2 (0x00007f472ed6b000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f472d0c6000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f472ce88000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f472cc69000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f472ca65000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f472c85f000)
> libglib2.0-0
> libnss3
> libx11-6
我一直在研究Ubuntu 16.04,所以这可能需要稍微调整一下14.04.根据安装的精简程度,您可能还需要libpcre或libstdc,但它们可能已经附带了其他软件包.
你可能还需要安装chrome,无论如何都要带上这些包.
Docker ubuntu 安装 chrome chromedriver
使用selenium时需要先安装chrome和chromedriver,以下是在Docker中安装的步骤
apt-get -y install xvfb gtk2-engines-pixbuf
apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
apt-get -y install imagemagick x11-apps
Xvfb -ac :99 -screen 0 1280x1024x16 & export disPLAY=:99
wget -q -O - http://dl.google.com/linux/linux_signing_key.pub | apt-key add -
sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
apt-get update -y
apt-get -y install google-chrome-stable
wget http://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip
apt-get -y install zip
apt-get -y install unzip
unzip chromedriver_linux64.zip
cp chromedriver /usr/bin/
今天关于在Ubuntu服务器上无头运行Chromedriver和ubuntu终端启动chrome的介绍到此结束,谢谢您的阅读,有关centos 无界面 服务器 安装chrome部署chromedriver、Chromedriver 在无头模式下运行不能加载插件、chromedriver:ubuntu 14.04 64位上缺少各种lib依赖项、Docker ubuntu 安装 chrome chromedriver等更多相关知识的信息可以在本站进行查询。
本文标签: