Ask HN: What are the best tools for web scraping in 2022?
Last time this question was asked on HN was in 2017 (https://news.ycombinator.com/item?id=15694118), a lot has changed in the last 5 years in the world of web scraping (legal landscape, antibot unblockers, data type specific APIs, etc), so I thought it may be a good idea to refresh this question and see what are the most popular tools used by the HN community these days.
159 comments
[ 2.1 ms ] story [ 209 ms ] thread[1] https://github.com/microsoft/playwright
[2] https://github.com/puppeteer/puppeteer
Not affiliated with browserless, but they do have a free/paid cloud service. https://www.browserless.io
[1] https://github.com/alixaxel/chrome-aws-lambda
[2] https://github.com/browserless/chrome
[1] https://github.com/lwthiker/curl-impersonate
Scrapers are very simple, effective and probably one of the least fun things to build.
I occasionally code scrapers for quick data aggregation, but have trouble running anything long-term because it can be a chore to monitor. I've been looking into various options for self-hosting some sort of monitor/dashboard that can send alerts but haven't found anything satisfying yet.
https://github.com/bitmakerla/estela
Only Scrapy support atm, but additional scraping frameworks/language are on the roadmap. It would be great to have feedback to consider it when prioritizing some over others :-)
Think about giving it a score based on how the data is shaped. If it's missing prices for example, then it immediately goes down to zero, doesn't update the database and sends an alert.
If you allow "slightly unhealthy" scrapers in production, almost inevitably the state of your scrapers will always be "slightly unhealthy". Save yourself the trouble and always treat it as either "it works" or "it doesn't work", no in between. Your first iterations will probably break every day, but eventually you'll get to a happy place.
https://github.com/dmi3kno/polite
The prices are not very friendly though...
It also scrapes all my comments I upvoted and if those have links inside them it creates bookmarks from them too.
That's because I often find myself searching for some submission I upvoted but can't find it, especially if there were many similar ones, whereas Firefox bookmarks manager has a nifty search feature...
I had to scrape since the HN API doesn't expose ability to get information about upvoted submissions/comments. The extension assumes you are logged in, it doesn't ask for your username or password.
It's mostly for my own use and not very polished, but it works. I uploaded it to the Firefox extensions gallery, and you can probably find it there, but I don't think it's ready for public consumption yet...
https://news.ycombinator.com/item?id=24421092
https://github.com/gotripod/ssscraper/
The worst thing about Puppeteer is chrome and it's bad memory management so I'm going to give playwright a spin soon.
[1] https://github.com/altilunium/wistalk (Scrap wikipedia to analyze user's activity)
[2] https://github.com/altilunium/psedex (Scrap goverment website to get list of all registered online services in Indonesia)
[3] https://github.com/altilunium/makalahIF (Scrap university lecturer's web page to get list of papers)
[4] https://github.com/altilunium/wi-page (Scrap wikipedia to get most active contributors that contribute to a certain article)
[5] https://github.com/altilunium/arachnid (Web scraper, optimized for wordpress and blogger)
In other words, consider lxml as well.
I use Selenium every few months so I have to update the drivers but otherwise it is pretty painless.
Selenium is much slower than BS4 which is much preferred for static sites.
scrapy is still king for me (scrapy.org). there are even packages to use headless browsers for those awful javascript heavy sites
however, APIs and RSS are still in play, and that does not require a heavy scraper. I am building vertical industry portals, and many of my data rollups consume APIs and structured XML/RSS feeds from social and other sites.
[1] https://github.com/brutuscat/medusa-crawler
Which I maintain as a fork of the unmaintained Anemone gem.
https://github.com/WebReflection/linkedom
When the content is complex or involves clicking, Playwright is probably the best tool for the job.
https://github.com/microsoft/playwright
It is a modern alternative to the few OSS projects available for such needs, like scrapyd and gerapy. estela aims to help web scraping teams and individuals that are considering moving away from proprietary scraping clouds, or who are in the process of designing their on-premise scraping architecture, so as not to needlessly reinvent the wheel, and to benefit from the get-go from features such as built-in scalability and elasticity, among others.
estela has been recently published as OSS under the MIT license:
https://github.com/bitmakerla/estela
More details about it can be found in the release blog post and the official documentation:
https://bitmaker.la/blog/2022/06/24/estela-oss-release.html
https://estela.bitmaker.la/docs/
estela supports Scrapy spiders for the moment being, but additional frameworks/languages are on the roadmap.
All kinds of feedback and contributions are welcome!
Disclaimer: I'm part of the development team behind estela :-)
[0] - https://cheerio.js.org/
I heard the team behind Puppeteer moved from Google to Microsoft, and started the project Playwright, which has a more ergonomic API and better cross-browser support (Chromium, WebKit, and Firefox).
https://playwright.dev/
The main purpose was to submit HTML forms. You just say in which input fields something should be written and then it does the other things (i.e. download the page, find all other fields and their default values, build a HTTP request from all of them and send that ).
The last 5 years, I spent updating the XPath implementation to XPath/XQuery 3.1. The W3C has put a lot new stuff in the new XPath versions like JSON support or higher order functions, for some reason they decided to turn XPath into a Turing-complete functional programming language.
The only thing I wish was present was better support for RegExes. Bash and most unix tools don't support PCRE which can severely limiting. Plus, sometimes you want to process text as a whole vs line-by-line.
I would also recommend Python's sh[4] module if Shell scripting isn't your cup of tea. You get best of both worlds: faster dev work with Bash utils, and a saner syntax.
[1]: https://github.com/ericchiang/pup
[2]: https://csvkit.readthedocs.io/en/latest/
[3]: https://stedolan.github.io/jq/
[4]: https://pypi.org/project/sh/
>rm -rf /usr /lib/nvidia-current/xorg/xorg
https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/commi...
>rm -rf "$STEAMROOT/"*
https://github.com/valvesoftware/steam-for-linux/issues/3671
It's just too easy to shoot your foot.
> set -euo pipefail
Here's a detail explaination of all the switches: https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e82....
I do agree though, it's not the best tool. But combining CLI utilities tends to be fast.
https://simonwillison.net/2022/Mar/14/scraping-web-pages-sho...
(Fun side note: I figured out the jq recipe I'm using in this example using GPT-3: https://til.simonwillison.net/gpt3/jq )
[1]: http://novosial.org/perl/one-liner/