Last updated: November 23, 2026
To scrape a web page with Python, you send an HTTP request with the Requests library, parse the returned HTML with Beautiful Soup, and select the elements you want by tag or class. This works for simple, static pages; it breaks on JavaScript-rendered content and rate limits. This guide shows the basic workflow, the most common failure points and what teams do next.
Scraping data with Python means using libraries such as Requests and Beautiful Soup to download a web page and extract specific elements from its HTML into a structured format like CSV or JSON.
Python gives developers simple tools to start scraping quickly, and scraping can unlock insights for pricing intelligence, market research or lead generation. This guide shows how to scrape data from a web page with Python, why scripts break, and what teams do to scale. For wider coverage, see Python scraping best practices and Python libraries for web extraction.
How Do You Scrape a Web Page With Python?
Python libraries such as Requests and Beautiful Soup handle the basics. This example extracts article titles from a page and saves them to CSV:
import csv
import requests
from bs4 import BeautifulSoup
URL = "https://example.com/articles" # replace with a page you are permitted to scrape
HEADERS = {"User-Agent": "my-scraper/1.0 (contact: you@example.com)"}
response = requests.get(URL, headers=HEADERS, timeout=10)
response.raise_for_status() # stop on 4xx/5xx errors
soup = BeautifulSoup(response.text, "html.parser")
titles = [h2.get_text(strip=True) for h2 in soup.find_all("h2", class_="article-title")]
with open("titles.csv", "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow(["title"])
writer.writerows([t] for t in titles)
print(titles)
The workflow:
- Send an HTTP request to the page (with a timeout and a status check).
- Parse the HTML with Beautiful Soup.
- Select elements by tag or class and save them.
Last tested: November 23, 2026, on Python 3.13 with Requests 2.34 and Beautiful Soup 4.15, against a local test page. The URL and selector are placeholders: swap in a page you are permitted to scrape.
For small projects and simple, static pages this approach works well. See also scraping tables with Python and scraping news websites with Python.
Check Permissions First
Before scraping, read the site’s robots.txt (the convention is defined in RFC 9309) and its terms of service, and look for an official API. Whether scraping is allowed depends on the site, the data and your use. See is web scraping legal?.
Which Python Tool Fits?
| Tool | Best for | Handles JavaScript? | Main limit |
|---|---|---|---|
| Requests + Beautiful Soup | Simple, static pages | No | Cannot run page scripts |
| Selenium | Pages that need a real browser | Yes | Slower, heavier |
| Playwright | Modern dynamic pages | Yes | Slower, heavier |
| Scrapy | Larger crawls | Not by itself | Steeper learning curve |
Why Does a Python Scraper Stop Working?
What If the Page Loads Data With JavaScript?
Many sites load content with JavaScript, and Requests plus Beautiful Soup cannot execute it, so the data may not be in the HTML you download. Use Selenium or Playwright to render the page, or check whether the site provides an API. See scraping JavaScript-heavy websites.
What Are Rate Limits and How Do You Avoid Them?
Sites monitor request frequency, and too many requests too quickly can be limited. Add delays between requests, keep volumes reasonable and respect the site’s stated limits.
Why Does My Scraper Get Blocked?
Sites may block IP addresses that send heavy traffic. Slow down, identify your scraper honestly and look for an API or a licensed data source. See rotating IPs in web scraping for how IP-based limits work.
When Should You Move Beyond a Python Script?
Scripts suit learning and testing. Across hundreds or thousands of pages, teams usually move to automated pipelines with retries and validation, add data cleaning and checks, and sometimes use a managed platform. See Python web scraping vs enterprise data extraction.
How Does Grepsr Fit In?
Grepsr offers managed data collection for teams that need scale. See its web scraping API and data as a service pages. Grepsr’s pricing page lists a Starter Pack from $100, priced on data records, at the time of this review (November 2026).
Last reviewed: November 23, 2026.
Frequently Asked Questions
How do you scrape a web page with Python?
Send an HTTP request with Requests, parse the HTML with Beautiful Soup, select elements by tag or class and save them, for example to CSV.
Why does my Python scraper stop working?
Common causes are JavaScript-rendered content, rate limits, blocks and changes to the site’s HTML.
Is it legal to scrape a website with Python?
It depends on the site’s terms, the data and your use. See is web scraping legal?.
How do I save scraped data to CSV?
Use Python’s built-in csv module, as in the example above, writing one row per scraped item.
What is the difference between Beautiful Soup and Scrapy?
Beautiful Soup parses HTML you have already downloaded; Scrapy is a framework that also handles requests, crawling and pipelines. See Python libraries for web extraction.
When should I move beyond a Python script?
When you need many pages, schedules, retries and validation, a pipeline or managed service may fit better.