将网页保存到 HTTP 存档¶
HTTP 存档文件以 JSON 格式捕获一系列 HTTP 请求和响应的完整详细信息。
shot-scraper har
命令可以保存一个 *.har.zip
文件,该文件包含 JSON 数据以及页面加载的任何资源的实际内容。
shot-scraper har https://datasette.com.cn/
这会保存到 datasette-io.har
。您可以使用 -o
指定文件名
shot-scraper har https://datasette.com.cn/tutorials/learn-sql \
-o learn-sql.har
一个 .har
文件是 JSON 格式的。您可以使用 Google HAR Analyzer 工具查看它。
HTTP 存档也可以创建为 .har.zip
文件。这些文件的格式略有不同:har.har
JSON 中不包含响应的完整内容,而是存储在 .zip
文件内的单独文件中。
要创建这种文件,请添加 --zip
标志
shot-scraper har https://datasette.com.cn/ --zip
或者指定一个以 .har.zip
结尾的文件名
shot-scraper har https://datasette.com.cn/ -o datasette-io.har.zip
您可以使用 unzip -l
查看 HAR zip 文件的内容
unzip -l datasette-io.har.zip
Archive: datasette-io.har.zip
Length Date Time Name
--------- ---------- ----- ----
39067 02-13-2025 10:33 41824dbd0c51f584faf0e2c4e88de01b8a5dcdcd.html
4052 02-13-2025 10:33 34972651f161f0396c697c65ef9aaeb2c9ac50c4.css
2501 02-13-2025 10:33 9f612e71165058f0046d8bf8fec12af7eb15f39d.css
10916 02-13-2025 10:33 2737174596eafba6e249022203c324605f023cdd.svg
5557 02-13-2025 10:33 427504aa6ef5a8786f90fb2de636133b3fc6d1fe.js
1393 02-13-2025 10:33 25c68a82b654c9d844c604565dab4785161ef697.js
1170 02-13-2025 10:33 31c073551ef5c84324073edfc7b118f81ce9a7d2.svg
1158 02-13-2025 10:33 1e0c64af7e6a4712f5e7d1917d9555bbc3d01f7a.svg
1161 02-13-2025 10:33 ec8282b36a166d63fae4c04166bb81f945660435.svg
3373 02-13-2025 10:33 5f85a11ef89c0e3f237c8e926c1cb66727182102.svg
1134 02-13-2025 10:33 3b9d8109b919dfe9393dab2376fe03267dadc1f1.svg
31670 02-13-2025 10:33 469f0d28af6c026dcae8c81731e2b0484aeac92c.jpeg
1157 02-13-2025 10:33 b7786336bfce38a9677d26dc9ef468bb1ed45e19.svg
50494 02-13-2025 10:33 har.har
--------- -------
154803 14 files
您可以使用 shot-scraper multi –har 选项将多个页面记录到单个 HTTP 存档中。
shot-scraper har --help
¶
此命令的完整 --help
信息
Usage: shot-scraper har [OPTIONS] URL
Record a HAR file for the specified page
Usage:
shot-scraper har https://datasette.io/
This defaults to saving to datasette-io.har - use -o to specify a different
filename:
shot-scraper har https://datasette.io/ -o trace.har
Use --zip to save as a .har.zip file instead, or specify a filename ending in
.har.zip
Options:
-z, --zip Save as a .har.zip file
-a, --auth FILENAME Path to JSON authentication context file
-o, --output FILE HAR filename
--wait INTEGER Wait this many milliseconds before taking the
screenshot
--wait-for TEXT Wait until this JS expression returns true
-j, --javascript TEXT Execute this JavaScript on the page
--timeout INTEGER Wait this many milliseconds before failing
--log-console Write console.log() to stderr
--fail Fail with an error code if a page returns an HTTP error
--skip Skip pages that return HTTP errors
--bypass-csp Bypass Content-Security-Policy
--auth-password TEXT Password for HTTP Basic authentication
--auth-username TEXT Username for HTTP Basic authentication
--help Show this message and exit.