@rickyChen
2016-08-09T15:40:36.000000Z
字数 742
阅读 6039
Python
yum install firefox -y
Selenium 是一个可以让浏览器自动化地执行一系列任务的工具
pip install selenium
pyvirtualdisplay is a python wrapper(封装) for Xvfb, Xephyr and Xvnc
yum install xorg-x11-server-Xvfb
pip install pyvirtualdisplay
CentOS 5.x
yum install fonts-chinese.noarch
CentOS 6.x(CentOS 6.x测试环境未成功)
yum groupinstall chinese-support
CentOS 7.x
yum groupinstall fonts
import time
from pyvirtualdisplay import Display
from selenium import webdriver
def screen_shot( driver, url ):
driver.get(url)
#等待10s,否则动态页面可能未加载完成
time.sleep(10)
driver.save_screenshot('home.png')
driver.close()
if __name__ == "__main__":
#定义窗口大小
display = Display(visible=0, size=(3057, 1349))
display.start()
browser = webdriver.Firefox()
screen_shot(browser, 'http://sina.com.cn')