You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(For this demo, use username = `root` and password = `password!`)
12
14
13
15
This will open a browser window on your computer showing the page you specified.
@@ -17,10 +19,10 @@ You can then sign in using that browser window - including 2FA or CAPTCHAs or ot
17
19
When you are finished, hit `<enter>` at the `shot-scraper` command-line prompt. The browser will close and the authentication credentials (usually cookies) for that browser session will be written out to the `auth.json` file.
18
20
19
21
To take authenticated screenshots you can then use the `-a` or `--auth` options to point to the JSON file that you created:
To contribute to this tool, first checkout the code. Then create a new virtual environment:
4
-
5
-
cd shot-scraper
6
-
python -m venv venv
7
-
source venv/bin/activate
8
-
6
+
```bash
7
+
cd shot-scraper
8
+
python -m venv venv
9
+
source venv/bin/activate
10
+
```
9
11
Or if you are using `pipenv`:
10
-
11
-
pipenv shell
12
-
12
+
```bash
13
+
pipenv shell
14
+
```
13
15
Now install the dependencies and test dependencies:
14
-
15
-
pip install -e '.[test]'
16
-
16
+
```bash
17
+
pip install -e '.[test]'
18
+
```
17
19
Then you'll need to install the Playwright browsers too:
18
-
19
-
shot-scraper install
20
-
20
+
```bash
21
+
shot-scraper install
22
+
```
21
23
To run the tests:
22
-
23
-
pytest
24
-
24
+
```bash
25
+
pytest
26
+
```
25
27
Some of the tests exercise the CLI utility directly. Run those like so:
26
-
27
-
tests/run_examples.sh
28
-
28
+
```bash
29
+
tests/run_examples.sh
30
+
```
29
31
## Documentation
30
32
31
33
Documentation for this project uses [MyST](https://myst-parser.readthedocs.io/) - it is written in Markdown and rendered using Sphinx.
32
34
33
35
To build the documentation locally, run the following:
34
-
35
-
cd docs
36
-
pip install -r requirements.txt
37
-
make livehtml
38
-
36
+
```bash
37
+
cd docs
38
+
pip install -r requirements.txt
39
+
make livehtml
40
+
```
39
41
This will start a live preview server, using [sphinx-autobuild](https://pypi.org/project/sphinx-autobuild/).
40
42
41
43
The CLI `--help` examples in the documentation are managed using [Cog](https://github.com/nedbat/cog). Update those files like this:
42
-
43
-
cog -r docs/*.md
44
-
45
-
## Tweeting the release notes
46
-
47
-
After pushing a release, I use the following to create a screenshot of the release notes to use in a tweet:
You can pass an `async` function if you want to use `await`, including to import modules from external URLs. This example loads the [Readability.js](https://github.com/mozilla/readability) library from [Skypack](https://www.skypack.dev/) and uses it to extract the core content of a page:
To use functions such as `setInterval()`, for example if you need to delay the shot for a second to allow an animation to finish running, return a promise:
Copy file name to clipboardExpand all lines: docs/multi.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,5 @@
1
+
(multi)=
2
+
1
3
# Taking multiple screenshots
2
4
3
5
You can configure multiple screenshots using a YAML file. Create a file called `shots.yml` that looks like this:
@@ -9,21 +11,21 @@ You can configure multiple screenshots using a YAML file. Create a file called `
9
11
url: https://www.w3.org/
10
12
```
11
13
Then run the tool like so:
12
-
13
-
shot-scraper multi shots.yml
14
-
14
+
```bash
15
+
shot-scraper multi shots.yml
16
+
```
15
17
This will create two image files, `www-example-com.png` and `w3c.org.png`, containing screenshots of those two URLs.
16
18
17
19
Use `-` to pass in YAML from standard input:
18
-
19
-
echo "- url: http://www.example.com" | shot-scraper multi -
20
-
20
+
```bash
21
+
echo"- url: http://www.example.com"| shot-scraper multi -
22
+
```
21
23
If you run the tool with the `-n` or `--no-clobber` option any shots where the output file aleady exists will be skipped.
22
24
23
25
You can specify a subset of screenshots to take by specifying output files that you would like to create. For example, to take just the shots of `one.png` and `three.png` that are defined in `shots.yml` run this:
24
-
25
-
shot-scraper multi shots.yml -o one.png -o three.png
26
-
26
+
```bash
27
+
shot-scraper multi shots.yml -o one.png -o three.png
28
+
```
27
29
The `url:` can be set to a path to a file on disk as well:
28
30
29
31
```yaml
@@ -36,15 +38,15 @@ Use the `--scale-factor` option to capture all screenshots at a specific scale f
36
38
For example, setting `--scale-factor 3` results in screenshots with a CSS pixel ratio of 3, which is ideal for emulating a high-resolution display, such as Apple's iPhone 12 screens.
37
39
38
40
To take screenshots with a scale factor of 3 (tripled resolution), run the following command:
39
-
40
-
shot-scraper multi shots.yml --scale-factor 3
41
-
41
+
```bash
42
+
shot-scraper multi shots.yml --scale-factor 3
43
+
```
42
44
This will multiply both the width and height of all screenshots by 3, resulting in images with a higher level of detail, suitable for scenarios where you need to capture the screen as it would appear on a high-DPI display.
43
45
44
46
Use `--retina` to take all screenshots at retina resolution instead, doubling the dimensions of the files:
45
-
46
-
shot-scraper multi shots.yml --retina
47
-
47
+
```bash
48
+
shot-scraper multi shots.yml --retina
49
+
```
48
50
Note: The `--retina` option should not be used in conjunction with the `--scale-factor` flag as they are mutually exclusive. If both are provided, the command will raise an error to prevent conflicts.
49
51
50
52
To take a screenshot of just the area of a page defined by a CSS selector, add `selector` to the YAML block:
0 commit comments