原文地址:https://lujun9972.github.io/blog/2020/04/11/從命令行獲取網站的截圖/index.html
今天從 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
經過測試,發現在打開了比較多 標籤頁
的情況下,截屏時間耗時特別長,感覺不是那麼實用。
Chrome
Chrome 也使用 --screenshot
選項進行截圖,但是還需要手工指定 --headless
來讓其運行在 headless
狀態下:
chrome --headless --screenshot="$filename.png" "$URL"
不過我不使用 chrome
瀏覽器,所以也沒有測試過。