从命令行获取网站的截图
Chrome 和 Firefox 都提供了一系列的 headless 功能,其中提供了对网站进行截屏的功能
Firefox
直接使用 Firefox 的 --screenshot
就能够进行截屏了,Firefox 会自动进入 headless
模式。关于 --screenshot
的说明如下:
firefox --help |grep screenshot
--screenshot [<path>] Save screenshot to <path> or in working directory. --window-size width[,height] Width and optionally height of screenshot.
所以,我们可以使用下面命令获取 baidu 的截图
firefox --screenshot images/firefox-baidu-screenshot.png https://www.baidu.com
经过测试,发现在打开了比较多 标签页
的情况下,截屏时间耗时特别长,感觉不是那么实用。
Chrome
Chrome 也使用 --screenshot
选项进行截图,但是还需要手工指定 --headless
来让其运行在 headless
状态下:
chrome --headless --screenshot="$filename.png" "$URL"
不过我不使用 chrome
浏览器,所以也没有测试过。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论