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

Create scraping.md #395

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Create scraping.md #395

wants to merge 3 commits into from

Conversation

fgregg
Copy link
Member

@fgregg fgregg commented Dec 20, 2024

Scraping guidance

This records the scraping guidance as discussed in #393

Scraping guidance
@fgregg fgregg requested a review from hancush December 20, 2024 21:01
Copy link
Member

@hancush hancush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of line edits, but otherwise this looks good. Thanks for capturing it, @fgregg!

etl/scraping.md Outdated
## Libraries
DataMade prefers that web scrapers use the [`scrapy` framework](https://scrapy.org/). Here's what we appreciate about scrapy:

1. Fast. `scrapy` wants to parallel, and so can pull a lot of data very quickly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a word here, maybe?

etl/scraping.md Outdated Show resolved Hide resolved
etl/scraping.md Outdated Show resolved Hide resolved
1. Fast. `scrapy` wants to parallel, and so can pull a lot of data very quickly.
2. Opinionated. `scrapy` scrapers expect files to be organized in particular ways. This is good for reviewing PRs.
3. Popular. `scrapy` is the most popular scraping framework, so you can find lots of QAs and extensions on the internet.
4. Extensible. If you need a scrapy that can run some javascript, you can stay within the `scrapy` framework and use middleware like [`scrapy-playwright`](https://github.com/scrapy-plugins/scrapy-playwright). If you need IP rotation or more advanced anti-bot circumventions, there is a good migration path from a normal scrapy script to [Zyte](https://scrapy-zyte-api.readthedocs.io/en/latest/).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for including this resource!

etl/scraping.md Outdated Show resolved Hide resolved
2. Tolerant error handling. With most of the serial, `requests`-based scrapers DataMade has written, if there is an exception, everything comes to a grinding halt and the process exits with a non-zero exit code. This is sometimes annoying, but makes it quite clear that something has gone wrong and it is easy to incorporate into longer data pipelines that should continue or not based upon exit codes (Makefiles, github actions are two examples). `scrapy` has another different philosophy, and every request you make could fail and the process would still exit successfully. If you only want to scrape without errors, then you need to affirmatively change a setting to exit on the first error, and [you need to do something like this](https://github.com/scrapy/scrapy/issues/1231#issuecomment-102409470) to change the exit code if there is an error.
3. Cache eviction. If you used `scrapy`'s caching mechanism, and you want to remove a small number of cached responses, it's pretty tricky to do the surgery to find the files and remove them.

We can put together a cookie cutter to help address some of those downsides.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open an issue for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

fgregg and others added 2 commits January 9, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants