Skip to content

Commit 0440199

Browse files
committed
1 parent a6ca48d commit 0440199

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

docs/har.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,13 @@ Usage: shot-scraper har [OPTIONS] URL
104104
Use --zip to save as a .har.zip file instead, or specify a filename ending in
105105
.har.zip
106106
107-
Use --extract / -x to also extract all resources from the HAR into a directory
107+
Use --extract / -x to also extract all resources from the HAR into a
108+
directory. With -x, you can specify a base path and the .har extension will be
109+
added automatically:
110+
111+
shot-scraper har https://datasette.io/ -x -o /tmp/datasette
112+
113+
This creates /tmp/datasette.har and extracts resources to /tmp/datasette/
108114
109115
Options:
110116
-z, --zip Save as a .har.zip file

shot_scraper/cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,12 +782,20 @@ def har(
782782
783783
Use --zip to save as a .har.zip file instead, or specify a filename ending in .har.zip
784784
785-
Use --extract / -x to also extract all resources from the HAR into a directory
785+
Use --extract / -x to also extract all resources from the HAR into a directory.
786+
With -x, you can specify a base path and the .har extension will be added automatically:
787+
788+
shot-scraper har https://datasette.io/ -x -o /tmp/datasette
789+
790+
This creates /tmp/datasette.har and extracts resources to /tmp/datasette/
786791
"""
787792
if output is None:
788793
output = filename_for_url(
789794
url, ext="har.zip" if zip_ else "har", file_exists=os.path.exists
790795
)
796+
elif extract and not (output.endswith(".har") or output.endswith(".har.zip")):
797+
# When -x is used with -o that lacks .har extension, treat as base path
798+
output = output + (".har.zip" if zip_ else ".har")
791799

792800
url = url_or_file_path(url, _check_and_absolutize)
793801
with sync_playwright() as p:

tests/test_shot_scraper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ def test_multi_har(http_server, args, expect_zip, record_shots):
354354
(["-x", "-z"], True),
355355
(["--extract", "-o", "output.har"], False),
356356
(["-x", "-o", "output.har.zip"], True),
357+
(["--extract", "-o", "basepath"], False), # base path without extension
358+
(["-x", "-z", "-o", "basepath"], True), # base path with zip
357359
),
358360
)
359361
def test_har_extract(http_server, args, expect_zip):

0 commit comments

Comments
 (0)