转储页面 HTML¶
通过 shot-scraper html
命令可以转储页面在所有 JavaScript 运行后的最终 HTML。
shot-scraper html https://datasette.com.cn/
使用 -o filename.html
将输出写入文件,而不是直接显示。
shot-scraper html https://datasette.com.cn/ -o index.html
添加 --javascript SCRIPT
可在获取 HTML 快照之前执行自定义 JavaScript。
shot-scraper html https://datasette.com.cn/ \
--javascript "document.querySelector('h1').innerText = 'Hello, world!'"
获取特定元素的 HTML¶
您可以使用 -s SELECTOR
选项来捕获页面上由 CSS 选择器标识的特定元素的 HTML。
shot-scraper html https://datasette.com.cn/ -s h1
输出如下
<h1>
<img class="datasette-logo" src="/static/datasette-logo.svg" alt="Datasette">
</h1>
shot-scraper html --help
¶
此命令完整的 --help
输出
Usage: shot-scraper html [OPTIONS] URL
Output the final HTML of the specified page
Usage:
shot-scraper html https://datasette.io/
Use -o to specify a filename:
shot-scraper html https://datasette.io/ -o index.html
Options:
-a, --auth FILENAME Path to JSON authentication context file
-o, --output FILE
-j, --javascript TEXT Execute this JS prior to saving the HTML
-s, --selector TEXT Return outerHTML of first element matching
this CSS selector
--wait INTEGER Wait this many milliseconds before taking the
snapshot
--log-console Write console.log() to stderr
-b, --browser [chromium|firefox|webkit|chrome|chrome-beta]
Which browser to use
--browser-arg TEXT Additional arguments to pass to the browser
--user-agent TEXT User-Agent header to use
--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
--silent Do not output any messages
--auth-password TEXT Password for HTTP Basic authentication
--auth-username TEXT Username for HTTP Basic authentication
--help Show this message and exit.