centos7服务器无GUI情况下安装使用Xvfb、selenium、chrome和selenium-server
来源:互联网 发布:qq飞车沙皇数据 编辑:程序博客网 时间:2024/05/04 23:13
</pre><pre>
最近需要用到selenium浏览器抓取,在windows下对照chrome浏览器开发的代码,在linux服务器上换成phantomjs驱动后,却不能运行了,通过截图发现phantomjs渲染效果和chrome不同。于是考虑在centos上安装chrome浏览器。
下面是做的一些记录。
1,centos7 安装 google-chrome
(1) 添加chrome的repo源
vi /etc/yum.repos.d/google.repo
[google]name=Google-x86_64baseurl=http://dl.google.com/linux/rpm/stable/x86_64enabled=1gpgcheck=0gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
(2)安装
yum update , 然后yum install google-chrome-stable
这时候在非root账号下运行google-chrome会输出没有显示器,无法启动之类的。
不知道为什么不能在root账号下运行。
2, 安装Xvfb
yum update
yum install Xvfb
yum -install libXfont
yum install xorg-x11-fonts*
3, 一个小测试
(1)安装selenium、pyvirtualdisplay
pip install selenium
pip install pyvirtualdisplay
(2)下载chromedriver
从https://sites.google.com/a/chromium.org/chromedriver/home下载chromedriver
配置在PATH路径或者在脚本中指定路径
(3) demo
vim test.py
# -*- coding:utf-8 -*-
from selenium import webdriverfrom pyvirtualdisplay import Displaydisplay = Display(visible=0, size=(800,600))display.start()driver = webdriver.Chrome("./chromedriver")driver.get("http://www.baidu.com")print driver.page_source
driver.quit()display.stop()
期望输出百度首页的html文档。4 ,selenium server
1, nohup Xvfb -ac :7 -screen 0 1280x1024x8 > /dev/null 2>&1 &
2, export DISPLAY=:7
3, java -jar selenium-server-standalone-3.0.1.jar
4,
<pre name="code" class="python"># -*- coding:utf-8 -*-from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesdriver = webdriver.Remote( command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME)driver.get("http://www.baidu.com")print driver.page_sourcedriver.quit()
0 0
- centos7服务器无GUI情况下安装使用Xvfb、selenium、chrome和selenium-server
- Centos7服务器无GUI情况下安装使用Xvfb+selenium+chrome
- XVFB实现selenium在linux上无界面运行安装篇
- Jenkins, xvfb and selenium
- ubuntu 自动化测试(selenium webdriver+chrome)结合Xvfb
- linux无界面下selenium安装及使用示例
- selenium 安装+ 调用chrome
- java+selenium什么情况下使用List
- selenium使用chrome浏览器
- Windows环境下Anaconda和selenium库安装使用
- 无显示器linux服务器下selenium+python+firefox爬虫
- selenium调用firefox和chrome
- Windows下python+selenium安装、使用
- ubuntu17.04下 selenium安装及使用
- PhantomJS、Selenium、Chrome驱动的mac版安装和配置
- 在linux下安装phantomjs和selenium
- win7下安装chromedriver和selenium测试
- Linux下安装selenium
- VB.net 研华IO卡1762的编程方法 控件方法 VS2010专业版
- Android BuildConfig.Debug 在module一直为false解决方案
- Linux常用指令及vi指令
- Android 6.0 杀进程,杀什么?
- 重新认识下NSAutoreleasePool
- centos7服务器无GUI情况下安装使用Xvfb、selenium、chrome和selenium-server
- android canvas实现在图片上画图
- java 字符串前置处理
- json数据解析
- iOS10 APP提交审核你会碰到的坑
- 正则表达式识别车牌
- nginx+tomcat 实现反向代理及负载均衡
- error: Error retrieving parent for item: No resource found that matches the given name 'android:Wind
- 取object对像中的数据