如何使用webscreenshot:从安装到批量截图的完整新手教程
【免费下载链接】webscreenshotA simple script to screenshot a list of websites项目地址: https://gitcode.com/gh_mirrors/we/webscreenshot
webscreenshot是一款简单实用的网站截图工具,能够帮助用户轻松实现批量网站截图功能。无论是需要对多个网站进行视觉记录,还是进行网站状态监控,webscreenshot都能提供高效便捷的解决方案。
📋 核心功能一览
webscreenshot作为一款专业的网站截图工具,具备以下强大特性:
- 多渲染器支持:兼容PhantomJS(推荐)、Chrome、Chromium和Firefox等多种渲染引擎
- 批量处理能力:支持从文件读取多个URL地址进行批量截图
- 高度自定义:可调整截图尺寸、格式、质量等参数
- 高级功能:支持cookie设置、自定义HTTP头、代理配置和基本认证
- 跨平台兼容:完全支持Windows和Linux系统运行
🚀 快速安装指南
系统要求
- Python 2.7或3.x环境
- 渲染引擎(PhantomJS、Chrome、Chromium或Firefox)
- 可选依赖:ImageMagick(用于添加URL标签功能)
安装步骤
方法一:使用pip安装(推荐)
pip install webscreenshot安装完成后,可直接通过webscreenshot命令使用
方法二:从源码安装
- 克隆仓库:
git clone https://gitcode.com/gh_mirrors/we/webscreenshot cd webscreenshot- 安装依赖:
pip install -r requirements.txt📝 基础使用教程
单个URL截图
最简单的使用方式是直接对单个URL进行截图:
python webscreenshot.py https://example.com截图默认保存在当前目录的screenshots文件夹中,文件名将自动基于URL生成。
批量URL截图
- 创建包含目标URL的文本文件(例如
list.txt),每行一个URL:
http://google.fr https://216.58.213.131 216.58.213.131 https://duckduckgo.com/robots.txt- 执行批量截图命令:
python webscreenshot.py -i list.txt⚙️ 常用参数配置
输出目录设置
使用-o参数指定截图保存目录:
python webscreenshot.py -i list.txt -o ./my_screenshots并行工作进程
使用-w参数设置并行处理的工作进程数(默认为4):
python webscreenshot.py -i list.txt -w 8截图尺寸调整
使用--window-size参数设置截图宽度和高度(默认为1200,800):
python webscreenshot.py -i list.txt --window-size 1920,1080渲染引擎选择
使用-r参数选择渲染引擎:
# 使用PhantomJS(默认,推荐) python webscreenshot.py -i list.txt -r phantomjs # 使用Chrome python webscreenshot.py -i list.txt -r chrome💡 高级使用技巧
添加URL标签
使用-l参数可以在截图底部添加URL标签(需要安装ImageMagick):
python webscreenshot.py -i list.txt -l --label-size 40设置代理
通过-P参数配置代理服务器:
python webscreenshot.py -i list.txt -P http://proxy.company.com:8080设置HTTP认证
如果目标网站需要基本认证,可以使用-u和-b参数提供用户名和密码:
python webscreenshot.py -i list.txt -u username -b password超时设置
使用-t参数设置截图超时时间(秒):
python webscreenshot.py -i list.txt -t 60❓ 常见问题解决
问题1:截图为空或显示证书错误
解决方案:如果使用Chrome/Chromium渲染器访问自签名证书的HTTPS网站,可能会出现此问题。建议切换到PhantomJS渲染器:
python webscreenshot.py -i list.txt -r phantomjs问题2:在无桌面环境的服务器上运行
解决方案:使用--no-xserver参数,需要系统安装xvfb:
python webscreenshot.py -i list.txt --no-xserver问题3:中文显示乱码
解决方案:确保系统已安装中文字体,或在自定义JS中设置合适的字体。
📚 完整参数说明
要查看所有可用参数,可以使用-h参数:
python webscreenshot.py -h这将显示webscreenshot的所有配置选项,包括输入处理、渲染器设置、图片参数、HTTP参数和连接参数等详细信息。
通过本教程,您已经掌握了webscreenshot的基本使用方法和高级技巧。无论是简单的单页截图还是复杂的批量网站截图任务,webscreenshot都能为您提供高效可靠的解决方案。开始使用webscreenshot,让网站截图工作变得简单而高效吧!
【免费下载链接】webscreenshotA simple script to screenshot a list of websites项目地址: https://gitcode.com/gh_mirrors/we/webscreenshot
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考