Users Pricing

blog

Home Blogs Requests, BeautifulSoup or Playwright? Web Scraping with Python Compared – MindStick
Requests, BeautifulSoup or Playwright? Web Scraping with Python Compared

Requests, BeautifulSoup or Playwright? Web Scraping with Python Compared

Veera Heikkinen 83 24 Nov 2026

You want prices from a supplier's catalogue, tender notices from a portal, or product details for comparison. The data is on a web page, there's no download button, and copying it by hand would take days.

Python is the go-to language for this. But "web scraping in Python" covers very different tools, and choosing the wrong one wastes hours. This guide compares the main options with working code, and covers the rules you should follow before scraping anything.

First: should you scrape at all?

Before writing code, check:

1. Is there an API or data export? Many sites offer an official API, RSS feed or CSV download. Use it. It's more reliable and clearly permitted.
2. What do the terms of service say? Some sites forbid automated access.
3. What does robots.txt say? It's at site.com/robots.txt and shows which paths the site asks bots not to crawl.
4. Is the data personal? Collecting personal information like names, phone numbers or emails brings data protection obligations, including under India's DPDP Act.
5. Is the content copyrighted? Collecting facts like prices is different from copying articles or images to republish.

This is general guidance, not legal advice. For commercial projects, check with a lawyer.

Option 1: Requests + BeautifulSoup (static pages)

If the data is in the page's HTML when you "View Source", this is the fastest and simplest approach.

- Requests downloads the page.
- BeautifulSoup parses the HTML so you can pick out elements with CSS selectors.

pip install requests beautifulsoup4

Running the built-in sample prints:

[{'name': 'Steel Bottle 1L', 'price': 649.0, 'url': '/p/101'},
{'name': 'Lunch Box Set', 'price': 1249.0, 'url': '/p/102'}]

Tips for this approach

- Find selectors with DevTools. Right-click an element → Inspect. Look for stable class names or IDs. Avoid long, fragile paths like div > div:nth-child(3) > span.
- Handle missing elements. Real pages are inconsistent; the code checks for None before reading text.
- Clean values. Strip currency symbols and commas before converting prices to numbers.
- Make URLs absolute with urllib.parse.urljoin(base_url, href).
- Use a session (requests.Session()) to reuse connections and keep cookies.

Pros: fast, lightweight, easy to run on a server or schedule. Cons: doesn't run JavaScript. If the content is loaded by JavaScript after the page opens, you'll get empty results.

How to tell if a page needs JavaScript

Open the page, then View Page Source (not Inspect). Search for a product name you can see on screen.

- Found in the source: Requests + BeautifulSoup will work.
- Not found: the page builds content with JavaScript. Try the next two options.

Option 2: Call the site's own data API

Many JavaScript-heavy sites load data from a JSON endpoint. Open DevTools → Network tab → filter by Fetch/XHR, then reload or scroll the page.

This is often faster and more reliable than parsing HTML. Check the terms of use: internal APIs aren't necessarily intended for public use, and they can change without notice.

Option 3: Playwright (JavaScript-heavy pages)

When content only appears after JavaScript runs, or you need to click, scroll, log in or fill forms, use a real browser. Playwright controls Chromium, Firefox or WebKit from Python.

pip install playwright
playwright install chromium

Tips for Playwright

- Wait for elements, not fixed times. wait_for_selector is more reliable than time.sleep.
- Block heavy resources like images and fonts to speed things up, using page.route.
- Reuse login sessions by saving storage state, instead of logging in for every run.
- Use page.content() to grab the rendered HTML and parse it with BeautifulSoup if you prefer its API.

Pros: handles anything a real user can see; can interact with pages. Cons: much slower and heavier; needs browser binaries installed; harder to run at scale.

Comparison

- Handles JavaScript content — Requests + BeautifulSoup: No; Site's JSON API: Yes (data source); Playwright: Yes
- Speed — Requests + BeautifulSoup: Fast; Site's JSON API: Fastest; Playwright: Slow
- Resource use — Requests + BeautifulSoup: Low; Site's JSON API: Low; Playwright: High (runs a browser)
- Robustness to layout changes — Requests + BeautifulSoup: Medium; Site's JSON API: High; Playwright: Medium
- Can click, scroll, log in — Requests + BeautifulSoup: Limited; Site's JSON API: No; Playwright: Yes
- Best for — Requests + BeautifulSoup: Static HTML pages; Site's JSON API: Sites with clean data endpoints; Playwright: Dynamic sites, interactions

There's also Scrapy, a full framework for large crawling projects, with scheduling, pipelines, retries and throttling built in. It's worth learning if you crawl many pages or many sites regularly.

Be a polite scraper

Scraping responsibly protects the website and keeps you from getting blocked:

- Slow down. Add delays between requests (the example waits two seconds). Don't run many parallel requests against a small site.
- Identify yourself with a clear User-Agent that includes contact details.
- Respect robots.txt and the site's terms.
- Cache pages you've already downloaded instead of fetching them again.
- Scrape during off-peak hours for large jobs.
- Don't try to bypass logins, paywalls or CAPTCHAs. If a site actively blocks automated access, take that as a no.
- Stop if asked. If the site owner contacts you, respect their wishes.

Making scrapers maintainable

Websites change, and scrapers break. Plan for it:

- Separate fetching from parsing, as in the example, so you can test parsing on saved HTML files.
- Write tests using saved sample pages.
- Log and alert when a scrape returns zero results or many missing fields. That usually means the layout changed.
- Store raw HTML for important jobs so you can re-parse without re-downloading.
- Schedule runs with Task Scheduler or cron, and save results to CSV, Excel or a database.

Choosing quickly

- Data visible in View Source? Use Requests + BeautifulSoup.
- Data loaded from a JSON endpoint you can see in the Network tab? Call it directly.
- Need to run JavaScript or interact with the page? Use Playwright.
- Crawling many pages or sites on a schedule? Consider Scrapy.
- An official API exists? Use that first, always.

Pick the lightest tool that works, scrape politely, and build for the day the website changes, because it will.


Veera Heikkinen

Lead Developer at Tietoevry

Working as Lead Developer with Tietoevry in Tampere. I have 9 years of experience in web services and cloud platforms, and earlier worked with Solita as Software Developer. I graduated from Tampere University with a BSc in Computer Science and completed an MSc in Computer Science at the same university. In my free time I like hiking in Lapland and fishing at our summer cottage.


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md