在linux环境下非GUI环境如何运行python+selenium
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 Display
from selenium import webdriver
import time
import sys
reload(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.title
browser.quit()
display.stop()