Skip to content

Commit

Permalink
- selector: support for YAML, closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Mar 9, 2022
1 parent a641589 commit 5f07a85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ jobs:
- output: examples/example.com.png
url: http://www.example.com/
- output: examples/w3c.org.png
url: https://www.w3.org/' | shot-scraper multi -
url: https://www.w3.org/
- output: examples/bighead-from-multi.png
url: https://simonwillison.net/
selector: "#bighead"
' | shot-scraper multi -
- name: Archive examples
uses: actions/upload-artifact@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
url: http://www.example.com/
- output: w3c.org.png
url: https://www.w3.org/
- output: simonwillison-bighead.png
url: https://simonwillison.net/
selector: "#bighead"
6 changes: 4 additions & 2 deletions shot_scraper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def shot(url, output, selector):
browser,
{
"url": url,
"selector": selector,
},
selector=selector,
return_bytes=True,
Expand All @@ -60,8 +61,8 @@ def shot(url, output, selector):
{
"url": url,
"output": str(output),
"selector": selector,
},
selector=selector,
)
browser.close()

Expand Down Expand Up @@ -103,7 +104,7 @@ def install():
run_module("playwright", run_name="__main__")


def take_shot(browser, shot, selector=None, return_bytes=False):
def take_shot(browser, shot, return_bytes=False):
url = shot.get("url") or ""
if not (url.startswith("http://") or url.startswith("https://")):
raise click.ClickException(
Expand All @@ -117,6 +118,7 @@ def take_shot(browser, shot, selector=None, return_bytes=False):
page = browser.new_page()
page.goto(url)
message = ""
selector = shot.get("selector")
if selector:
if return_bytes:
return page.locator(selector).screenshot()
Expand Down

0 comments on commit 5f07a85

Please sign in to comment.