1、linux系统下已经安装好python2.7和selenium
2、linux系统下安装服务:
安装Xvfb
yum install Xvfb
yum -install libXfont
yum install xorg-x11-fonts*
3、python用pip安装
install pyvirtualdisplay
使用:
#coding=utf-8
from pyvirtualdisplay import Displayfrom selenium import webdriverimport timeimport sysreload(sys)sys.setdefaultencoding( "utf-8" )display=Display(visible=0,size=(800,600))
display.start()# now Firefox will run in a virtual display.
# you will not see the browser.browser=webdriver.Firefox()
browser.get("http://www.baidu.com")time.sleep(3)print browser.titlebrowser.quit()
display.stop()