前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >一个python版的开源web截图工具:

一个python版的开源web截图工具:

作者头像
py3study
发布2020-01-15 10:55:22
1.3K0
发布2020-01-15 10:55:22
举报
文章被收录于专栏:python3python3

一个python版的开源web截图工具:python-webkit2png

http://github.com/AdamN/python-webkit2png/ 一个使用pyqt4里的QtWebkit实现的命令行的web截图软件,可用于服务器端的web截图 貌似是个比较新的项目,以前找过类似的工具,没有多好用的,但是这个真的很好用,看一下参数就知道了

Creates a screenshot of a website using QtWebkit.This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the terms of the GNU General Public License v2. Options: --version show program's version number and exit -h, --help show this help message and exit -x WIDTH HEIGHT, --xvfb=WIDTH HEIGHT Start an 'xvfb' instance with the given desktop size. -g WIDTH HEIGHT, --geometry=WIDTH HEIGHT Geometry of the virtual browser window (0 means 'autodetect') [default: (0, 0)]. -o FILE, --output=FILE Write output to FILE instead of STDOUT. -f FORMAT, --format=FORMAT Output p_w_picpath format [default: png] --scale=WIDTH HEIGHT Scale the p_w_picpath to this size --aspect-ratio=RATIO One of 'ignore', 'keep', 'crop' or 'expand' [default: none] -F FEATURE, --feature=FEATURE Enable additional Webkit features ('javascript', 'plugins') -w SECONDS, --wait=SECONDS Time to wait after loading before the screenshot is taken [default: 0] -t SECONDS, --timeout=SECONDS Time before the request will be canceled [default: 0] -W, --window Grab whole window instead of frame (may be required for plugins) --style=STYLE Change the Qt look and feel to STYLE (e.G. 'windows'). -d DISPLAY, --display=DISPLAY Connect to X server at DISPLAY. --debug Show debugging information. --log=LOGFILE Select the log output fileCreates a screenshot of a website using QtWebkit.This program comes withABSOLUTELY NO WARRANTY. This is free software, and you are welcome toredistribute it under the terms of the GNU General Public License v2.Options: --version show program's version number and exit -h, --help show this help message and exit -x WIDTH HEIGHT, --xvfb=WIDTH HEIGHT Start an 'xvfb' instance with the given desktop size. -g WIDTH HEIGHT, --geometry=WIDTH HEIGHT Geometry of the virtual browser window (0 means 'autodetect') [default: (0, 0)]. -o FILE, --output=FILE Write output to FILE instead of STDOUT. -f FORMAT, --format=FORMAT Output p_w_picpath format [default: png] --scale=WIDTH HEIGHT Scale the p_w_picpath to this size --aspect-ratio=RATIO One of 'ignore', 'keep', 'crop' or 'expand' [default: none] -F FEATURE, --feature=FEATURE Enable additional Webkit features ('javascript', 'plugins') -w SECONDS, --wait=SECONDS Time to wait after loading before the screenshot is taken [default: 0] -t SECONDS, --timeout=SECONDS Time before the request will be canceled [default: 0] -W, --window Grab whole window instead of frame (may be required for plugins) --style=STYLE Change the Qt look and feel to STYLE (e.G. 'windows'). -d DISPLAY, --display=DISPLAY Connect to X server at DISPLAY. --debug Show debugging information. --log=LOGFILE Select the log output fileCopy Code

使用举例: 使用之前安装依赖的包

sudoapt-getinstall python-qt4sudo apt-get install python-qt4Copy Code

OK,可以用了,假如在用ubuntu桌面版的话就很简单了

#加上运行权限 chmod +x ./webkit2png.py #高度设置为0,就可以获得整个页面的截图了 ./webkit2png.py -g10240 http://bluehua.org -o test.png#加上运行权限 chmod +x ./webkit2png.py#高度设置为0,就可以获得整个页面的截图了./webkit2png.py -g 1024 0 http://bluehua.org -o test.pngCopy Code

假如运行在服务器上,没有x环境,则需要安装一些额外的依赖包

#安装xvfb用于虚拟X环境 apt-getinstall xvfb #安装中文字体 apt-getinstall xfonts-wqy #配置字体 fontconfig-voodoo -f-s zh_CN#安装xvfb用于虚拟X环境apt-get install xvfb#安装中文字体apt-get install xfonts-wqy#配置字体fontconfig-voodoo -f -s zh_CNCopy Code

运行时需要加额外的参数

#x选项用于指定虚拟出来的X桌面的尺寸 ./webkit2png.py -x1024768-g10240 http://bluehua.org -o test.png#x选项用于指定虚拟出来的X桌面的尺寸./webkit2png.py -x 1024 768 -g 1024 0 http://bluehua.org -o test.pngCopy Code

恩,其实我找这个东西的目的是想在服务器端获取一个页面的实际渲染宽度,目的达成~

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-06-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档