Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design and implement selector shots #8

Closed
simonw opened this issue Mar 9, 2022 · 3 comments
Closed

Design and implement selector shots #8

simonw opened this issue Mar 9, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Mar 9, 2022

Goal here is to be able to take a screenshot of a specific component of the page, identified by a CSS selector.

Should work for both multi and single shot mode.

@simonw simonw added the enhancement New feature or request label Mar 9, 2022
@simonw
Copy link
Owner Author

simonw commented Mar 9, 2022

https://playwright.dev/python/docs/screenshots

page.locator(".header").screenshot(path="screenshot.png")

@simonw
Copy link
Owner Author

simonw commented Mar 9, 2022

In single shot mode:

shot-scraper https://simonwillison.net -s "#bighead"

In YAML:

- url: https://simonwillison.net/
  output: simonwillison.net.png
  selector: "#bighead"

simonw added a commit that referenced this issue Mar 9, 2022
@simonw
Copy link
Owner Author

simonw commented Mar 9, 2022

Testing multi with this demo.yml file:

- output: example.com.png
  url: http://www.example.com/
- output: w3c.org.png
  url: https://www.w3.org/
- output: simonwillison-bighead.png
  url: https://simonwillison.net/
  selector: "#bighead"
% shot-scraper multi demo.yml
Screenshot of 'http://www.example.com/' written to 'example.com.png'
Screenshot of 'https://www.w3.org/' written to 'w3c.org.png'
Screenshot of '#bighead' on 'https://simonwillison.net/' written to 'simonwillison-bighead.png'

That last one produced this:

simonwillison-bighead

@simonw simonw closed this as completed in 5f07a85 Mar 9, 2022
simonw added a commit that referenced this issue Mar 9, 2022
simonw added a commit that referenced this issue Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant