python + selenium + phantomjs 截图
1、phantomjs下载地址http://phantomjs.org/download.html
2、windows上使用下载即可用,linux上需要安装【bitmap-fonts bitmap-fonts-cjk】否则截取的图中不显示中文
linux中不显示中文即没有安装相应的字体,我们安装字体即可:
在centos中执行:yum install bitmap-fonts bitmap-fonts-cjk
在ubuntu中执行:sudo apt-get install xfonts-wqy
3、截图代码 - python
import time
from selenium import webdriver
from settings.config import EXECUTABLE_PATH
import warnings
warnings.simplefilter("ignore")
def screen_shot(link, save_path):
browser = webdriver.PhantomJS(executable_path=EXECUTABLE_PATH)
browser.maximize_window()
browser.get(link)
flag = browser.get_screenshot_as_file(save_path)
browser.quit()
return flag
if __name__ == '__main__':
url = "http://jyzx.xiangyang.gov.cn/jyxx/gcjs/zbjggg/202112/t20211230_2680240.shtml"
path = r"D:\project\python_project\myproject\JFa_ggzy\666.png"
fla, e = screen_shot(link=url, save_path=path)
|