8

从命令行获取网站的截图

 3 years ago
source link: https://www.lujun9972.win/blog/2020/04/11/%E4%BB%8E%E5%91%BD%E4%BB%A4%E8%A1%8C%E8%8E%B7%E5%8F%96%E7%BD%91%E7%AB%99%E7%9A%84%E6%88%AA%E5%9B%BE/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

从命令行获取网站的截图

今天从 https://www.putorius.net/website-screenshot-linux-command-line.html 学到了一招。

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

firefox-baidu-screenshot.png

经过测试,发现在打开了比较多 标签页 的情况下,截屏时间耗时特别长,感觉不是那么实用。

Chrome

Chrome 也使用 --screenshot 选项进行截图,但是还需要手工指定 --headless 来让其运行在 headless 状态下:

chrome --headless --screenshot="$filename.png" "$URL"

不过我不使用 chrome 浏览器,所以也没有测试过。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK