您当前的位置:首页 > 计算机 > 软件应用 > 浏览器应用

从命令行获取网站的截图

时间:12-14来源:作者:点击数:

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 浏览器,所以也没有测试过。

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐