Skip to content

How to scrape a website: the main approaches compared

By the ProxyOnly team · 16 Nov 2026 · 7 min read

Seven ways to get data out of a website, from an official API to a headless browser, with a tested comparison of HTML parsing and JSON endpoints.

To scrape a website means to have a program read its pages and pull out the data. There is more than one way to do it, and the best one is often the least scraper-like. Each approach below is a different trade between effort, speed, fragility and how well it fits the site's rules. The order is roughly from the easiest and most stable to the heaviest.

We tested the three that need no extra software on quotes.toscrape.com, a practice site that exists to be scraped. The code in this article is what we ran, and the numbers are what it printed. A practice site is friendlier than the real web, so treat the numbers as an illustration of the differences and not as a benchmark.

Before you write any code

Two checks come first, because they decide whether and how you should scrape.

  • Read the site's terms and its robots.txt. The robots standard, RFC 9309, says a crawler that fetches the file must follow its rules. If the file is unavailable with a 4xx response, a crawler may access anything. If the server is unreachable or answers with a 5xx error, the crawler must assume everything is disallowed. Is web scraping legal covers terms, privacy law and the cases that went to court.
  • Look for something better than scraping: an official API, a data export, an RSS feed or a dataset you can download. These are the sanctioned route for programs, and they are less likely to break.

Python's own urllib.robotparser has two traps. Its read() method fetches the file with the default urllib user agent, which some sites refuse, and it treats a 401 or 403 answer as "everything is disallowed". We tested the second point with a local server that answered robots.txt with a 401, and can_fetch returned False. A safer pattern is to fetch the file yourself with your own client and a descriptive user agent, handle the status code, and pass the text to parse():

import urllib.robotparser
import requests
UA = "my-scraper/1.0 (+https://my-site.example/bot)"
response = requests.get("https://quotes.toscrape.com/robots.txt", headers={"User-Agent": UA}, timeout=20)
if response.status_code >= 500 or response.status_code in (401, 403):
    raise SystemExit(f"robots.txt answered {response.status_code}: do not crawl until you know the rules")
robots = urllib.robotparser.RobotFileParser()
robots.parse(response.text.splitlines() if response.ok else [])
print(response.status_code, robots.can_fetch(UA, "https://quotes.toscrape.com/page/2/"))

It printed 404 True. The practice site has no robots.txt, so nothing is disallowed.

The approaches

1. An official API or data feed

Use it if it exists and has the fields you need. It is documented, stable and usually allowed by the terms. The costs are limits on volume, missing fields, and sometimes a fee or an approval process.

2. Parse the HTML

When the data is in the page's source, which you can check with "view source" in a browser, download the page and extract it with a parser. Libraries such as Beautiful Soup, covered in our Beautiful Soup guide, find elements by CSS selector. This is the standard starting point for a static site.

import time
from bs4 import BeautifulSoup
session = requests.Session()
session.headers["User-Agent"] = UA
quotes = []
for page in range(1, 11):
    html = session.get(f"https://quotes.toscrape.com/page/{page}/", timeout=20).text
    for card in BeautifulSoup(html, "html.parser").select("div.quote"):
        quotes.append((card.select_one("span.text").get_text(), card.select_one("small.author").get_text()))
    time.sleep(0.2)
print(len(quotes), quotes[0][1])

It printed 100 Albert Einstein: ten pages, ten quotes each. The weakness is fragility. When the site changes its markup, your selectors stop matching, so check counts and fail loudly when they drop.

3. Call the JSON behind the page

Many pages load their data from a separate request. Open the browser's developer tools, go to the Network tab, filter by Fetch or XHR and reload or scroll. If you see a request that returns JSON with your data, calling it directly is usually faster and cleaner than parsing HTML. The practice site's infinite-scroll page does exactly this.

quotes, page = [], 1
while True:
    data = session.get("https://quotes.toscrape.com/api/quotes", params={"page": page}, timeout=20).json()
    quotes += [(q["text"], q["author"]["name"]) for q in data["quotes"]]
    if not data["has_next"]:
        break
    page += 1
    time.sleep(0.2)
print(len(quotes))

It printed 100, and the list matched the one from the HTML run exactly. The catch is that such an endpoint is not documented, so it can change without notice, and the site's terms may treat it differently from its public pages. Read them first.

4. Read the data embedded in the page

Some pages that look dynamic carry their data inside a script tag, and JavaScript turns it into elements when the page loads. A parser that looks for div.quote finds nothing, because the elements do not exist yet. The data is there, though. On the practice site's /js/ page we found zero div.quote elements and a var data = [...] assignment holding ten quotes:

import json, re
html = session.get("https://quotes.toscrape.com/js/", timeout=20).text
data = json.loads(re.search(r"var data = (\[.*?\]);", html, re.S).group(1))
print(len(data), data[0]["author"]["name"])

It printed 10 Albert Einstein. Many pages also embed their data as a JSON block for search engines, so look for script tags before you reach for a browser.

5. Drive a headless browser

When the data only appears after scripts run, or after clicks, logins and scrolling, use a real browser engine controlled by code. Playwright, Selenium and Puppeteer are the common choices, and our integration pages cover Selenium and Puppeteer. It handles almost any page and it is the slowest and heaviest option, because each page runs a full browser. We did not run a headless browser in this test. Use it when approaches 3 and 4 fail, not as the first choice.

6. A crawling framework

For thousands of pages or a job that repeats, a framework adds what a script lacks: queues, retries, concurrency limits, deduplication and exports. Scrapy, Crawlee and Colly are well known, and we have guides for Scrapy, Crawlee and Colly. They organize the work and do not change the rules about politeness and terms.

7. A hosted service or no-code tool

If you would rather not maintain scrapers, services run them for you, and some sell ready-made datasets. You give up control and pay for it, but for a small or one-off job it can cost less than your time. Check that the provider's way of collecting data fits the site's terms, because the responsibility for what you use is yours.

What our test showed

We timed the HTML and JSON approaches with a small script that counts requests and downloaded bytes. Both collected the same 100 quotes, with a 0.2 second pause between requests:

A  HTML pages     : 100 quotes, 10 requests, 106 KB downloaded, 3.9s
B  JSON endpoint  : 100 quotes, 10 requests, 30 KB downloaded, 3.1s
same quotes from both? True

The JSON endpoint moved less than a third of the data and finished a little sooner. Over 100 quotes the difference is small, and over a million records it adds up in bandwidth, time and proxy cost. It is also the reason to look at the network tab before you write a parser.

How to choose

  1. If an API or a feed gives you the data, use it.
  2. If the data is in the page source, parse the HTML.
  3. If it appears after scrolling or clicking, look for the JSON request in the network tab.
  4. If the page has the data in a script tag, read it from there.
  5. If none of that works, use a headless browser, and keep it as slim as you can.
  6. If the job is large or recurring, wrap the chosen method in a crawling framework.

Collect politely

  • Send a descriptive User-Agent that names your tool and links to a page about it, and slow down. A pause between requests is the cheapest form of politeness. Rate limiting for scrapers explains how to find a pace a site tolerates.
  • Honor 429 and 503 responses and the Retry-After header. 503 Service Unavailable shows a retry setup that does.
  • Keep the pages and data you already have, so that you do not fetch them again.
  • Collect only what you need, and think about personal data before you store it.
  • Know what a block looks like, so that you stop and think when you meet one. Why websites block IPs and proxies lists the signals and 403 Forbidden explains the most common refusal.

Where proxies fit

Most small scraping jobs need no proxy at all. A proxy helps when a site limits requests per address and your job is large, when the content depends on the visitor's country, or when you need to see a site as visitors in another place do. Proxies for web scraping explains when they help and when they do not, and what is web scraping is a good place to start if the basics are new. The web scraping use case page shows how our proxies fit into such a project.

Try it yourself

Create an account, add funds from US$1 and order a proxy in the country you need.

Keep reading