小编向大家介绍过phantomjs,还介绍过phantomjs实现网络爬虫的方法,phantomjs是基于webkit内核的无界面浏览器,处理可以用于网络爬虫,还可以获取网页的内容及截图。本文向大家介绍phantomjs实现截图的代码实例以及截屏容易出现的两种错误的解决方法。
一、phantomjs下载
官网下载:http://phantomjs.org/download.html
二、phantomjs截图实现
第一步:确定截屏内容
from selenium import webdriver as wd
bro = wd.PhantomJS(executable_path='./phantomjs-2.1.1-windows/bin/phantomjs')
bro.get('https://www.baidu.com')第二步:截屏的操作
bro.save_screenshot('./1.png')
text = bro.find_element_by_id('kw')
text.send_keys('人名币')第三步:找到动作按钮,点击操作
button = bro.find_element_by_id('su')
button.click()第四步:完成截屏
bro.save_screenshot('./2.png')
bro.quit()三:截屏容易出现的错误
1、PhantomJs预览页有图,导出页面为空白。
解决:地址调用头拼错,需要修改。
2、中文字体不展示
解决:缺少字体包,需安装字体包
linux执行命令:
yum install bitmap-fonts bitmap-fonts-cjk
以上就是phantomjs截图的实现代码及容易出现错误的解决方法,希望能对你有所帮助哦~



