A scraper that was working perfectly yesterday now returns an empty page, and you haven't touched the code in the slightest. That's the reality of scraping a real site. The content is now loaded via JavaScript, or the results are hidden behind pagination, dynamic filters, and a login. The responses crawl, the requests get blocked, and the HTML structure changes completely a week after you've even shipped the thing. A lot of those failures are down to one very early decision you made: which tool you chose.
I've used a fair bit of Python tooling to deal with those sorts of problems, and none of them is universally the best. Some are absolutely brilliant for little scripts; others are far and away the best for large-scale scraping or for sites that only serve their data once the browser has actually run the page.
This guide looks at seven of the tools: Requests, Beautiful Soup, Playwright, Scrapy, Selenium, HTTPX and Selectolax. For each, we look at what it does and where it fits in, with some practical examples. By the end of it, you'll know which one I'd reach for first on a new project and the quick check that will tell you when you can just as well ignore the heavyweight tools entirely.
What Makes a Good Python Web Scraping Tool?
Before picking a tool, think about what you're trying to collect.
If you only need product names and prices from a simple HTML page, you probably don't need a full browser automation framework. A lightweight HTTP client and an HTML parser may be enough.
If the site loads product details after JavaScript runs, you'll likely need a browser-based tool. And if you're collecting data from thousands of pages, a framework with built-in request scheduling and concurrency saves a lot of work.
Here's what I look at when choosing a scraping tool:
- Ease of use: Can I get a basic scraper running without too much setup?
- Speed: How long does it take to send requests and process HTML?
- JavaScript support: Can it handle pages that load content dynamically?
- Concurrency: Can it process multiple pages without making the code hard to manage?
- Data extraction: Does it make it easy to select elements and pull out text or attributes?
- Error handling: Can I manage timeouts, failed requests, and retries?
- Scalability: Will it still work when the project grows from a few pages to thousands?
No single tool wins in every situation. The right choice depends on the website and how much data you need.
1. Requests

If I need to fetch a simple web page with Python, Requests is usually the first tool I reach for.
It's a popular HTTP library that makes sending requests straightforward, so you don't have to deal with low-level networking details just to download a page.
Requests works when the site returns the data you need in its initial HTML response. You send a GET request, read the response, and pass the HTML to a parser such as Beautiful Soup.
What Makes Requests Useful?
- Simple syntax for sending HTTP requests
- Support for GET, POST, PUT, DELETE, and other methods
- Custom headers and query parameters
- Cookies and session handling
- Authentication support
- Timeout settings
- Connection handling through sessions
One thing to know: Requests doesn't run JavaScript. If a site builds its product listings in the browser after the page loads, Requests won't show you that content.
Basic Example
Say you want to download a web page and check its status code.
import requests
url = "https://example.com"
response = requests.get(
url,
headers={
"User-Agent": "Mozilla/5.0"
},
timeout=15
)
if response.status_code == 200:
print(response.text)
else:
print("Request failed:", response.status_code)
The response.text property gives you the page's HTML as text, which you can hand to Beautiful Soup or Selectolax to extract what you need.
For a reusable scraper, I'd add proper exception handling:
import requests
def fetch_page(url):
try:
response = requests.get(url, timeout=15)
response.raise_for_status()
return response.text
except requests.exceptions.Timeout:
print("The request timed out")
except requests.exceptions.RequestException as error:
print("Request error:", error)
return None
That keeps your script from stopping every time a request fails.
Best for: Small scraping scripts, static HTML pages, simple data collection, and projects where you need a straightforward HTTP client.
Official website: https://requests.readthedocs.io/
2. Beautiful Soup

Requests can download a page, but it doesn't make extracting information from HTML especially convenient. That's where Beautiful Soup comes in.
Beautiful Soup is an HTML and XML parsing library. It helps you find elements, read their text, extract links, and work with the page structure.
I find it useful when the HTML is already in the response, and it's beginner-friendly because the methods are easy to follow.
What Makes Beautiful Soup Useful?
- Simple HTML and XML parsing
- Search by tag, class, ID, and attributes
- Extract text and links
- Navigate between parent and child elements
- Handle imperfect HTML
- Work with different HTML parsers
Beautiful Soup doesn't download pages by itself. You usually pair it with Requests or HTTPX to fetch the HTML.
Basic Example
Imagine you want to collect article titles from a blog page.
import requests
from bs4 import BeautifulSoup
url = "https://example.com/blog"
response = requests.get(url, timeout=15)
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
titles = soup.find_all("h2")
for title in titles:
print(title.get_text(strip=True))
The find_all() method returns matching elements. You can also search for a specific class:
articles = soup.find_all(
"div",
class_="article-card"
)
for article in articles:
title = article.find("h2")
if title:
print(title.get_text(strip=True))
This is helpful when you've got a site with a repetitive HTML structure (e.g., product cards, article listings, job postings, etc.).
Beautiful Soup or Requests?
They're not direct alternatives. Requests will get the page, and Beautiful Soup will parse the HTML. For many small scraping tasks, using them together is enough:
- Requests downloads the page.
- Beautiful Soup reads the HTML.
- Your Python code extracts the required data.
- You save the results to CSV, JSON, or a database.
Best for: Beginners, static websites, blog scraping, product listings, and extracting structured information from HTML.
Official documentation: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
3. Playwright

Some sites don't serve up all their content in the initial HTML. They'll load the data in after the page has loaded; they'll respond to user actions; they'll use JavaScript to populate the page, etc.
In those cases, a basic HTTP request may not be enough, and you need a browser that can open the page and run its JavaScript.
Playwright is a browser automation tool that supports Chromium, Firefox, and WebKit. With Python, you can control a browser, wait for page content, click buttons, fill forms, and collect information from rendered pages.
It's one of the first tools I consider when a site needs browser interaction.
What Makes Playwright Useful?
- Supports Chromium, Firefox, and WebKit
- Runs JavaScript in the browser
- Handles dynamic page content
- Supports browser contexts and sessions
- Can interact with buttons, forms, and menus
- Provides automatic waiting for many page actions
- Supports screenshots and browser downloads
- Works with asynchronous Python code
Basic Example
First, install Playwright:
pip install playwright
playwright install
Now you can open a page and collect its title:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto(
"https://example.com",
wait_until="domcontentloaded"
)
print(page.title())
browser.close()
You can also wait for a specific element before extracting its content.
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto("https://example.com/products")
page.locator(".product-card").first.wait_for()
products = page.locator(".product-card").all()
for product in products:
name = product.locator("h2").inner_text()
print(name)
browser.close()
The selectors in this example are placeholders. Inspect the actual site and use selectors that match its HTML.
When Should You Use Playwright?
- Playwright helps when:
- Product details appear after JavaScript runs.
- You have to click the 'load more' button.
- Search results update without a full page reload.
- You need to work with browser sessions.
- A page requires form input or other user actions.
It uses more resources than a simple HTTP request because it runs a browser, so I wouldn't use it for every scraping job.
Best for: JavaScript-heavy websites, dynamic content, browser-based workflows, and pages that need user interaction.
Official documentation: https://playwright.dev/python/
4. Scrapy

When a scraping project grows, managing every request, response, retry, and output file by hand gets difficult.
Scrapy is a Python web scraping framework built for larger crawling and data collection tasks. Instead of writing the whole workflow yourself, you use its built-in features to manage requests, follow links, process responses, and export data.
It's especially useful when you need to crawl many pages from the same website.
What Makes Scrapy Useful?
- Built-in request scheduling
- Asynchronous request handling
- Concurrent crawling
- Automatic link following
- Retry support
- Data pipelines
- Feed exports such as JSON and CSV
- Middleware for handling requests and responses
- Controls for crawl delays and request limits
Scrapy takes a different approach from Requests and Beautiful Soup. You write a spider that tells Scrapy which URLs to visit and what to extract.
Basic Example
Install Scrapy:
pip install scrapy
Create a spider:
import scrapy
class BlogSpider(scrapy.Spider):
name = "blog"
start_urls = [
"https://example.com/blog"
]
def parse(self, response):
for article in response.css(".article-card"):
yield {
"title": article.css("h2::text").get(),
"url": article.css("a::attr(href)").get()
}
Run it from your Scrapy project:
scrapy crawl blog -O articles.json
Scrapy visits the starting URL, runs the parse() method, and saves the results to a JSON file. You can extend the spider to follow pagination links, visit article pages, and collect more fields.
Why Use Scrapy Instead of a Simple Script?
Say you need to collect information from 5,000 product pages. With a basic script, you'd have to manage the request queue, concurrency, retries, and output handling yourself. Scrapy already provides a structure for all of that, so you can spend more time on the site's data and less on building a crawler from scratch.
Scrapy doesn't run website JavaScript by default, though. When the content only appears after JavaScript runs, you may need to connect it to a browser automation tool or another solution.
Best for: Large crawling projects, multi-page websites, product catalogs, directories, and structured data collection.
Official documentation: https://docs.scrapy.org/
5. Selenium

Selenium is another widely used browser automation tool. It allows a Python developer to control a browser and interact with a website as a human would: open a page, click a button, fill in a form, select from a drop-down, etc., then read the content that appears once the page has loaded.
It's been around a long time, is widely used for browser testing, and can also work for scraping sites that depend on browser interaction.
What Makes Selenium Useful?
- Supports major browsers
- Can interact with page elements
- Handles JavaScript-rendered content
- Supports browser sessions
- Works with forms and dropdowns
- Provides explicit waits
- Useful for automated testing and scraping workflows
Basic Example
Install Selenium:
pip install selenium
Now open a website and collect its title:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
print(driver.title)
headings = driver.find_elements(
By.TAG_NAME,
"h2"
)
for heading in headings:
print(heading.text)
finally:
driver.quit()
You can also wait for an element to appear before trying to read it:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
try:
driver.get("https://example.com/products")
first_product = WebDriverWait(driver, 15).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR, ".product-card")
)
)
print(first_product.text)
finally:
driver.quit()
That's better than a fixed sleep because the script waits for the element instead of always pausing for the same amount of time.
Selenium vs Playwright
Both can control browsers and deal with dynamic sites. Playwright has a modern API and some very useful built-in waiting. Selenium has a long history in browser automation and is widely used in testing. For a new browser-based scraping project, I'd normally start with Playwright. However, Selenium is still a perfectly viable option, particularly if you're already using it or your project is built around it.
Best for: Browser automation, dynamic websites, form-based workflows, and projects that already use Selenium for testing.
Official documentation: https://www.selenium.dev/documentation/
6. HTTPX

HTTPX is a modern Python HTTP client. It's very much like Requests in many respects; the key difference being that it supports asynchronous requests. You can therefore make several requests and fetch several pages without having to wait for one to finish before starting the next. It supports both sync and async code, so it's suitable for a range of Python applications.
What Makes HTTPX Useful?
- Sync and async APIs
- HTTP/1.1 and HTTP/2 support
- Timeout configuration
- Custom headers and cookies
- Connection pooling
- Authentication support
- Streaming responses
- Async client support
The async feature matters most for scraping projects that make many independent requests.
Basic Async Example
Install HTTPX:
pip install httpx
Now fetch multiple pages:
import asyncio
import httpx
async def fetch_page(client, url):
response = await client.get(url)
response.raise_for_status()
return response.text
async def main():
urls = [
"https://example.com",
"https://example.org",
"https://example.net"
]
async with httpx.AsyncClient(timeout=15) as client:
tasks = [
fetch_page(client, url)
for url in urls
]
pages = await asyncio.gather(*tasks)
for page in pages:
print(len(page))
asyncio.run(main())
This example makes the requests run in parallel. In a real scraper, you'd want to limit the concurrency and deal with individual request failures so that one bad URL doesn't bring the whole thing to a halt.
When Should You Choose HTTPX?
HTTPX makes sense when:
- You need asynchronous HTTP requests.
- You're collecting data from many static pages.
- You're building an async Python application.
- You want an HTTP client that supports both sync and async code.
Like Requests, HTTPX doesn't run JavaScript. If the content you're after only appears as a result of JavaScript executing, then you're going to need a browser automation tool.
Best for: Async scraping, API data collection, and projects that need to fetch many pages efficiently.
Official documentation: https://www.python-httpx.org/
7. Selectolax

Selectolax is an HTML parser built for fast parsing and CSS selector-based extraction.
When a scraper downloads a lot of HTML, parsing speed starts to matter. Selectolax is a useful option when you want to extract information from HTML without a browser, and it's especially interesting if you already know CSS selectors and want a lightweight way to work with page content.
What Makes Selectolax Useful?
- Fast HTML parsing
- CSS selector support
- Lightweight parsing workflow
- Text and attribute extraction
- Useful for large HTML documents
- Works well with Requests or HTTPX
Selectolax doesn't send HTTP requests. You need an HTTP client to download the page first, then pass the HTML to the parser.
Basic Example
Install Selectolax:
pip install selectolax
Now extract article titles:
import requests
from selectolax.parser import HTMLParser
url = "https://example.com/blog"
response = requests.get(url, timeout=15)
response.raise_for_status()
tree = HTMLParser(response.text)
for node in tree.css("h2"):
print(node.text(strip=True))
You can also extract links:
for link in tree.css("a"):
text = link.text(strip=True)
href = link.attributes.get("href")
if text and href:
print(text, href)
That gives you a simple way to collect text and attributes from matching elements.
Selectolax vs Beautiful Soup
Both libraries parse HTML, but they differ in their strengths. Beautiful Soup is famous for its easy-to-use API and its ability to handle all sorts of malformed HTML. Selectolax is a good choice if you're after speed of parsing and the use of CSS selectors. For a small project, Beautiful Soup may be easier to start with; for a scraper that's going to process a lot of pages, Selectolax is definitely worth a look.
Best for: Fast HTML parsing, big scrapes, and developers who just prefer to use CSS selectors.
Official repository: https://github.com/rushter/selectolax
Quick Comparison: 7 Python Web Scraping Tools
Here's a quick overview of where each tool fits.
| Tool | Main Purpose | JavaScript Support | Best Use Case |
|---|---|---|---|
| Requests | Send HTTP requests | No | Simple page fetching |
| Beautiful Soup | Parse HTML and XML | No | Extracting data from HTML |
| Playwright | Browser automation | Yes | Dynamic websites |
| Scrapy | Web crawling framework | Not by default | Large crawling projects |
| Selenium | Browser automation | Yes | Browser-based workflows |
| HTTPX | Sync and async HTTP requests | No | Concurrent page fetching |
| Selectolax | Fast HTML parsing | No | High-speed HTML extraction |
These tools don't all do the same job. Requests and HTTPX fetch pages. Beautiful Soup and Selectolax parse HTML. Playwright and Selenium control browsers. Scrapy manages the crawling process.
You can combine them as your requirements demand. Requests with Beautiful Soup is a common setup for small projects, while HTTPX with Selectolax can work well for async scraping.
Which Python Web Scraping Tool Should You Choose?
If I had to pick one tool for every scraping project, I'd probably pick wrong.
A scraper that collects ten pages from a blog has different needs from one that tracks product prices across thousands of URLs. The best tool depends on how the site works and how much data you need. Here's how I'd choose:
- For Simple Static Websites: This combo is simple to understand and straightforward to set up. Requests will download the HTML, and Beautiful Soup will then extract what you require. Use it for blogs, directories, basic product pages, and any other site where the data is in the initial HTML.
- For JavaScript-Heavy Websites: Choose Playwright when you need a browser to display the page. It's the tool to use for dynamic lists, filters, buttons, and browser sessions.
- For Large Crawling Projects: If you need to go through tens of thousands of pages, follow links, and manage a large request queue,e then Scrapy is the framework for the job.
- For Browser Automation: Selenium is a good fit if your project already uses it or needs browser interactions that fit its automation setup.
- For Async Requests: If your scraper needs to fetch many pages at the same time, HTTPX gives you an async option without a browser.
- For Faster HTML Parsing: If you already have the HTML and want to parse it quickly, Selectolax is worth a look.
Practical Tips for Building a Reliable Python Scraper
Choosing the right library is only part of the job. A scraper also has to handle real-world problems. Here are a few practices I'd build in from the start.
1. Set Request Timeouts
Never let your script wait forever for a response.
response = requests.get(url, timeout=15)
A timeout gives your application a limit and helps it recover when a server is slow or unavailable.
2. Handle Errors Properly
A site can return a 404, a 403, or a 500. Your scraper shouldn't be treating every response as valid HTML.
Check the status code and handle exceptions before extracting data.
3. Use Retries Carefully
Temporary network failures do occur, and a retry can be useful in such circumstances; just don't keep sending requests without some kind of limit.
Use a small retry count with backoff and respect the site's rate limits.
4. Avoid Sending Too Many Requests
Sending hundreds of requests at once will simply overwhelm the site and get your IP blocked.
Set sensible concurrency limits, include appropriate delays, and comply with the site's terms and any applicable access rules.
5. Keep Selectors Easy to Update
Websites will change their HTML, and a class name that's currently working may well be gone after a redesign.
Keep your selectors in one place if you can and make sure the extracted fields are empty before you save them.
6. Save Data in a Useful Format
For smaller projects, CSV and JSON are quite often sufficient. For bigger projects, you may want to consider a database such as PostgreSQL.
Don't go saving the duplicates. A product ID or page URL will tell you which ones you've already got.
7. Keep Logs
When a scraper runs for hours, errors printed to the terminal aren't the end of the world.
Use Python's logging module to log the failed URLs, the response codes, the number of times you've retried, and the extraction errors. That makes it much easier to track down problems later.
Final Thoughts
Python has several good web scraping tools available, and the best one depends on the job at hand.
For simple pages, Requests and Beautiful Soup are a pretty good combo. If you're after faster HTML parsing, then Selectolax is worth a look. HTTPX is useful if you're doing asynchronous requests, and Scrapy is the full framework if you're doing a large-scale crawl. When you've got JavaScript in the way, then Playwright and Selenium are your only real options, as you have to work through a real browser.
If I were doing a new scraping project from scratch today, I'd first look at how the site serves up the content. If it's all in the HTML, then I'd just go with a very lightweight scraper and skip the browser automation entirely. If it's a case of needing JS or some user interaction, then I'd test Playwright.
Pick the simplest tool that collects the data reliably and copes with how the site really behaves, even when a more powerful one is available.
Frequently Asked Questions (FAQs)
1. Which Python library is best for web scraping?
The best python libraries for web scraping are Requests with Beautiful Soup, which work well for simple static websites; Playwright suits dynamic page; and Scrapy is a strong choice for large crawling projects.
2. Is Beautiful Soup better than Selenium?
They do different jobs. Beautiful Soup parses HTML you already have, while Selenium controls a browser. They do quite different things. Beautiful Soup is for parsing HTML that you already have. Selenium is for controlling a browser and can therefore interact with pages that are generated via JavaScript. So Beautiful Soup is your tool for static HTML; Selenium is the one to use if you need to interact with a page that's been dynamically generated.
3. Can Requests scrape JavaScript websites?
Requests can download the initial HTML, but it doesn't execute JavaScript. If the site loads its data after the browser opens, use a browser automation tool such as Playwright or Selenium, or check whether the site provides an accessible data endpoint.
4. Is Scrapy faster than Beautiful Soup?
They're not direct alternatives. Beautiful Soup is an HTML parser. Scrapy is a crawling framework. Scrapy can handle concurrent requests and large-scale crawls; you can certainly use Beautiful Soup in a bespoke scraping workflow too.
5. Should I use Playwright or Selenium for web scraping?
Both can automate browsers and pick up JavaScript-rendered content. Playwright is a good starting point for many new browser-based projects, given its modern API and built-in waiting. Selenium is also a good option, particularly if you're already in the browser automation and testing space.
Top comments (3)
That opening line hit home. 😅 "Worked yesterday, empty page today" is basically the unofficial scraping job description.
I like your "simplest tool that works" rule. Before reaching for Playwright, I open the browser's Network tab and look for the XHR/fetch call that loads the data. Often it's a clean JSON endpoint, so httpx plus a few headers does the job, and you skip the browser entirely. It's usually 10x faster and breaks less when the UI changes.
Another thing I'd add is that picking the tool is only half the battle. Once you scale, blocks and 403s become the real problem. Rotating IPs, sensible delays, and retries with backoff often matter more than which library you chose.
The
HTTPX + Selectolaxcombo for async scraping is underrated too. 🔥Curious: Do you check for hidden JSON endpoints first, or go straight to Playwright when you see JS-rendered content?
Thanks! That opening line was written from painful experience, so I'm glad it landed. 😄
Honest answer: I check for hidden JSON endpoints first, almost every time. My routine is to load the page with DevTools open on the Network tab, filter by Fetch/XHR, and reload. If a clean JSON response shows up, I copy it as cURL, strip it down to the headers that matter, and replay it with httpx. When it works, it's faster, cheaper, and far less likely to break when the frontend gets redesigned.
I only go to Playwright when there's no usable endpoint. That usually means the data comes from signed or short-lived tokens, heavy client-side rendering, or flows that depend on real browser behavior like logins, infinite scroll, or anti-bot checks that fingerprint the browser.
You're also right that scale is a different problem from tool choice. Once you're making thousands of requests, proxy rotation, polite delays with jitter, and retries with exponential backoff matter more than whether you picked httpx or Playwright. I should have made that point stronger in the post.
And yes, HTTPX + Selectolax is a seriously underrated pair. 🔥 Thanks for the thoughtful comment!
Loved the closing advice to pick the simplest tool that works. Most people jump straight to Playwright when they hit a JS-heavy site, and that's often overkill. 😄
One trick I'd add to your "check how the site serves content" step: open DevTools → Network → Fetch/XHR before launching a browser. Many "JavaScript-rendered" pages just pull their data from a clean JSON endpoint. Hit that directly with HTTPX and you skip the browser, the parsing, and most selector breakage. It's usually 10x faster too.
The HTTPX + Selectolax combo for async scraping is underrated. Great pick. 🔥
Quick question: When a site changes its HTML after you've shipped, do you have any monitoring to catch silent breakage, like alerting when extracted fields suddenly come back empty? That's the failure that hurts me most in production.