Engineering

What Are BeautifulSoup, Playwright and Scrapy?

Three Python tools for reading the web programmatically, each solving a different part of the problem.

Definition

BeautifulSoup is an HTML parsing library, Playwright is a browser automation library that drives a real rendering engine, and Scrapy is a crawling framework that manages requests at scale. They are complementary rather than competing, and most non trivial projects use more than one.

BeautifulSoup: parsing

BeautifulSoup takes a string of HTML and gives you a navigable tree. It does not fetch pages and it does not execute JavaScript. It is the right tool when you already have the markup and need to pull specific elements out of it, and it tolerates malformed HTML well.

Playwright: rendering

Playwright controls a real browser, so the page is fetched, scripts execute, and the resulting DOM is what a user would see. That makes it the tool for content that only exists after JavaScript runs, and for measuring the gap between the raw response and the rendered page. The cost is that a browser is far heavier than an HTTP request.

Scrapy: crawling at scale

Scrapy is a framework rather than a library. It handles scheduling, concurrency, retries, throttling, deduplication of URLs and item pipelines. When the job is thousands of pages rather than a handful, that infrastructure is the difficult part and Scrapy already has it.

Crawling responsibly

  • Respect robots.txt and any stated crawl delay
  • Identify your crawler honestly in the user agent string
  • Rate limit so the target site is not degraded by your requests
  • Cache responses so a re-run does not refetch unchanged pages
  • Check the terms of service before collecting data at scale

Playwright enables reliable end-to-end testing for modern web apps, with a single API across Chromium, Firefox and WebKit.

Playwright documentation

References