Difference Between an API and a Scraper
Learn how consuming an API differs from scraping a website: stability, permission, structure, rate limits, and why an API is almost always preferable.
Both get you data from someone else's system. An API is a door the owner built and labelled; scraping is reading the shop window and transcribing what you see. Both can work β but only one comes with a contract, and that difference shapes everything downstream.
1. What Is an API?
An API is a documented interface a provider publishes so programs can request data directly.
- Key idea: the provider intends this use and defines the shape of the response.
- Mechanism: an HTTP request to a documented endpoint, usually authenticated, returning JSON.
- Comes with: documentation, versioning, rate limits, terms, and β critically β a stable contract.
Example of an API
GET /api/v2/products/1234
β {"id":1234,"name":"...","price":19.99,"currency":"USD","in_stock":true}
Typed fields, predictable structure, and a version number telling you when it may change.
2. What Is a Scraper?
A scraper extracts data from pages built for human readers.
- Key idea: you are deriving structure the provider never promised.
- Mechanism: fetch HTML, apply selectors, convert presentation back into data.
- Comes with: nothing. No contract, no versioning, no notice of change.
Example of a Scraper
price = tree.css_first(".product-price").text() # "$19.99"
You then strip the currency symbol, parse the number, and handle the day it becomes "From $19.99" or "Sale: $17.99 was $19.99". Every one of those is presentation, not data, and every one can change without warning.
3. Key Differences
| API | Scraper | |
|---|---|---|
| Intended use | Yes, by design | Not usually |
| Structure | Defined and typed | Inferred from markup |
| Stability | Versioned, with deprecation notice | Changes without warning |
| Data types | Real numbers, booleans, dates | Strings needing parsing |
| Completeness | Fields the provider chose to expose | Whatever is rendered |
| Rate limits | Documented | Unstated, enforced by blocking |
| Authentication | API key or OAuth | Usually none, or a session |
| Efficiency | Small JSON payload | Full page β HTML, CSS, images |
| Legal position | Governed by explicit terms | Depends on terms, robots.txt, jurisdiction |
| Failure mode | Clear error codes | Silent empty fields |
4. Why an API Wins Whenever One Exists
The efficiency gap alone is large β a JSON response may be 2 KB where the page is 800 KB, so you transfer four hundred times less to get the same values. But the decisive advantage is the contract.
Example to Illustrate
A retailer redesigns its product pages. Every scraper targeting them breaks the same afternoon: selectors miss, fields come back empty, and unless someone asserted on record counts the pipeline quietly stores nulls.
The same redesign changes nothing for API consumers. The frontend was rebuilt; /api/v2/products still returns the same schema, because it is versioned and the provider committed to it.
That is the real difference. Scraping means your data pipeline is coupled to someone else's presentation layer β the part of their system that changes most often and that they change most freely.
5. When Scraping Is the Right Answer
Scraping is not a lesser technique; it is the technique for when no door exists.
- There is no API. Common, and the primary legitimate reason.
- The API omits what you need. Plenty expose a subset β no pricing history, no reviews, no ranking position.
- The API is prohibitively expensive or gated behind a partnership you cannot obtain.
- You need what the user sees, which is the whole point for SERP data, ad verification, and localised pricing β the rendered result is the data.
- Coverage across many providers, where a hundred sites means a hundred API integrations, if they even exist.
6. How to Check for an API First
This step is skipped constantly and takes minutes:
- Open DevTools β Network β Fetch/XHR and reload. Modern sites fetch their own data from internal JSON endpoints. That endpoint is usually cleaner and more stable than the rendered markup, even when undocumented.
- Look for
/api/,/graphql, or.jsonURLs in the page source. - Check for
__NEXT_DATA__or a similar embedded blob β the data is already JSON, sitting in the HTML. - Search the provider's developer documentation. Many APIs are simply not advertised on the marketing site.
- Check for a data export, feed, or sitemap, which solves URL discovery for free.
Finding the XHR endpoint behind a page is often the single highest-value thing you can do before writing a scraper.
7. Summary
An API is a contract; scraping is an inference. The API gives you typed fields, versioning, documented limits, and vastly smaller payloads. Scraping gives you access when no API exists, when it omits what you need, or when the rendered page is itself the thing you are measuring.
Always check for an API first β including the undocumented internal endpoints visible in the Network tab, which frequently deliver the same data as clean JSON. When you do scrape, treat it as coupling to a presentation layer that can change without notice, and build accordingly: stable selectors, saved fixtures, and assertions that fail loudly rather than storing nothing quietly.