Skip to content

Commit

Permalink
--browser option for shot-scraper auth, closes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 8, 2022
1 parent a574d66 commit 1978e3f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,32 @@ To take authenticated screenshots you can then use the `-a` or `--auth` options
shot-scraper https://datasette-auth-passwords-demo.datasette.io/ \
-a auth.json -o authed.png

Full `--help` for `shot-scraper auth`:

<!-- [[[cog
result = runner.invoke(cli.cli, ["auth", "--help"])
help = result.output.replace("Usage: cli", "Usage: shot-scraper")
cog.out(
"```\n{}\n```\n".format(help.strip())
)
]]] -->
```
Usage: shot-scraper auth [OPTIONS] URL CONTEXT_FILE
Open a browser so user can manually authenticate with the specified site, then
save the resulting authentication context to a file.
Usage:
shot-scraper auth https://github.com/ auth.json
Options:
-b, --browser [chromium|firefox|chrome|chrome-beta]
Which browser to use
-h, --help Show this message and exit.
```
<!-- [[[end]]] -->

## Taking multiple screenshots

You can configure multiple screenshots using a YAML file. Create a file called `shots.yml` that looks like this:
Expand Down
13 changes: 10 additions & 3 deletions shot_scraper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ def install(browser):
"context_file",
type=click.Path(file_okay=True, writable=True, dir_okay=False, allow_dash=True),
)
def auth(url, context_file):
@browser_option
def auth(url, context_file, browser):
"""
Open a browser so user can manually authenticate with the specified site,
then save the resulting authentication context to a file.
Expand All @@ -486,8 +487,14 @@ def auth(url, context_file):
shot-scraper auth https://github.com/ auth.json
"""
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
context = browser.new_context()
context, browser_obj = _browser_context(
p,
auth=None,
interactive=True,
devtools=True,
browser=browser,
)
context = browser_obj.new_context()
page = context.new_page()
page.goto(url)
click.echo("Hit <enter> after you have signed in:", err=True)
Expand Down

0 comments on commit 1978e3f

Please sign in to comment.