centos7无GUI情况安装Xvfb、selenium、chrome
2019獨角獸企業重金招聘Python工程師標準>>>
centos7服務器無GUI情況下安裝使用Xvfb、selenium、chrome和selenium-server
2016年10月31日 15:24:24?閱讀數:12192更多
個人分類:?centosselenium
?
</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 webdriver
from pyvirtualdisplay import Display
display = 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 webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = 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_source
driver.quit()
轉載于:https://my.oschina.net/u/3367404/blog/1982340
總結
以上是生活随笔為你收集整理的centos7无GUI情况安装Xvfb、selenium、chrome的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Reservoir Computing:
- 下一篇: 安全测试===sqlmap(零)转载
