Capture screenshot and/or HTML source code data of any given webpage and print it to stdout.
Output format: JSON string containing b64-encoded data.
- Uses Google Chrome in headless mode.
- Works well even with vertically long webpages.
- Webpages with fixed headers generally work well, but fixed footers may lead to unusual results.
Forked and modified from: https://github.com/mokemokechicken/docker_capture_web
Tested on the following environment
- Linux 6.6
- Docker Version 24.0.7
./build
Then either run
./capture <URL> [options]
or alternatively run
docker run --cap-drop=all --security-opt=no-new-privileges --rm elliotwutingfeng/take_a_shot <URL> [options]
{
"screenshot": "<PNG screenshot as b64-encoded string>",
"source_code": "<HTML source code as b64-encoded string>"
}
docker run --cap-drop=all --security-opt=no-new-privileges --rm elliotwutingfeng/take_a_shot "https://example.com"
docker run --cap-drop=all --security-opt=no-new-privileges --rm elliotwutingfeng/take_a_shot "https://example.com" --window-size 390x844 --ua 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/113.0 Mobile/15E148 Safari/605.1.15'
usage: takeashot.py [-h] [--screenshot] [--source-code]
[--window-size WINDOW_SIZE] [--ua USER_AGENT]
[--wait WAIT] [--lang LANG] [--language LANGUAGE] [-v]
[--vv]
url
positional arguments:
url specify URL
options:
-h, --help show this help message and exit
--screenshot Take screenshot
--source-code Extract source code
--window-size WINDOW_SIZE
specify window size like 1200x800
--ua USER_AGENT specify user-agent
--wait WAIT specify wait seconds after scroll down
--lang LANG set LANG environment variable
--language LANGUAGE set LANGUAGE environment variable
-v set LogLevel to INFO
--vv set LogLevel to DEBUG