Testing
Short answer
Web scraping is the automated extraction of publicly accessible data from websites into a structured format. A program requests a page the same way a browser does, reads the returned HTML, selects the specific values you asked for, and writes them out as CSV, JSON or database rows — repeated across hundreds or millions of pages.
It is used when a site holds data you need and offers no API, or offers an API that omits the fields you care about.
Key Takeaways
- Scraping automates access, it does not create it. A scraper requests the same public page a browser does.
- Crawling finds pages; scraping extracts fields. Most production systems need both.
- Client-rendered pages cost roughly 10x more to scrape than server-rendered ones, because they require a headless browser.
- Maintenance, not development, is the dominant cost. Sites change layouts and scrapers fail silently.
- Legality turns on what you collect, not on automation. Personal data, creative works and login-gated pages are the three risk zones.
- In India, three regimes apply: the DPDP Act 2023, the Copyright Act 1957 and the IT Act 2000.
WEB SCRAPING AT A GLANCE
| Also known as | Web data extraction, web harvesting, screen scraping, data scraping | |||||
| What it produces | Structured records — CSV, JSON, Markdown, database rows | |||||
| Core components | Crawler, fetcher, renderer, parser, extractor, validator, store | |||||
| Dominant language | Python (Scrapy, BeautifulSoup, Playwright); Node.js for JS-heavy targets | |||||
| Main legal constraints | Privacy law (GDPR, DPDP Act), copyright, computer-misuse statutes, contract | |||||
| Main technical constraints | Anti-bot detection, JavaScript rendering, rate limits, layout drift | |||||
| Primary 2026 use case |
Supplying training corpora and retrieval data for AI systems |
|||||
What this guide covers
- The definition, precisely
- Scraping vs crawling vs APIs vs data mining
- How a scraper works: the eight stages
- A working example in Python
- Static vs dynamic pages — the fork that decides your cost
- The types of web scrapers
- Why scraping gets hard at scale
- What web scraping is used for
- Scraping for AI: training data, RAG and agents
- Is web scraping legal?
- The legal position in India
- An ethical scraping checklist
- Build or buy: an honest comparison
- Glossary
- Frequently asked question
The definition, precisely
Web scraping — also called web data extraction or web harvesting — is the use of software to retrieve web pages and pull specific values out of them automatically, converting unstructured page markup into structured records.
The distinction that matters is structure. A web page is designed to be read by a person: prices sit inside styled <span> tags, specifications hide in tables built for visual layout, and the same field appears in a different place on every site. A scraper's job is to reverse that presentation and recover the underlying data model — product, price, currency, availability, timestamp — in a form a database or a model can consume.
If you have ever copied a table off a website into a spreadsheet, you have performed a manual scrape. Automation changes the economics, not the concept: the same operation across 50,000 pages, on a schedule, with validation.
Key point
Scraping does not create access. It automates access you already have as an ordinary visitor. That framing is what most of the legal analysis later in this guide turns on.
Scraping vs crawling vs APIs vs data mining
These four terms get used interchangeably and they are not the same thing.
| Term | What it does | Output | Typical tool |
|---|---|---|---|
| Web crawling | Discovers pages by following links across a site or the open web | A list of URLs | Scrapy, a sitemap parser |
| Web scraping | Extracts named fields from a specific page | Structured records | BeautifulSoup, lxml, a scraping API |
| API consumption | Requests data through an interface the owner publishes and supports | Structured records, versioned | An HTTP client |
| Data mining | Finds patterns in data you already hold | Insights, models |
pandas, scikit-learn |
In practice, crawling and scraping are two halves of one system. The crawler answers "which pages?" and the scraper answers "what's on them?" A search engine is almost entirely crawler. A price monitor pointed at 200 known product URLs is almost entirely scraper. Most real projects sit in between.
When an API exists, use the API
This is worth stating plainly because it is the single most common mistake. If the site publishes an API that returns the fields you need, that path is cheaper, faster, legally cleaner and does not break when someone redesigns the page. Scraping is the fallback for the very large share of the web that offers no such interface — or offers one that deliberately withholds the interesting fields.
How a scraper works: the eight stages

| 01 |
Define target and schemaName the pages and write down the exact fields you want before writing any code. A schema fixed up front — |
| 02 |
Discover URLsCollect the page list from a sitemap, a category listing, a search result set, or by crawling links. Sitemaps are underused and are usually the cheapest source. |
| 03 |
FetchIssue an HTTP |
| 04 |
Render, if requiredIf the content is assembled by JavaScript, a plain fetch returns an empty shell. A headless browser executes the scripts, waits for the network to settle, and hands back the finished DOM. |
| 05 |
ParseTurn the HTML string into a navigable tree. Where the page is powered by an internal JSON endpoint, reading that response directly is faster and far more stable than parsing markup. |
| 06 |
ExtractSelect values with CSS selectors, XPath, regular expressions, or an extraction model that infers fields from structure rather than fixed paths. |
| 07 |
Clean and validateNormalise currencies, dates and units. Strip whitespace, deduplicate, and reject rows that fail the schema. Silent bad data is worse than a loud failure. |
| 08 |
Store and monitorWrite to CSV, JSON, Postgres or a warehouse — then watch the extraction rate. A scraper that returns 40% null on a field it filled yesterday has broken, and nothing will tell you unless you check. |
Stage 08 is where scraping projects live or die. Writing the scraper is a day's work. Keeping it correct through two years of site redesigns is the actual engineering problem.
A working example in Python
Here is a complete scraper against a site that exists specifically to be practised on. It fetches a page, parses it, extracts two fields per record, and writes structured output.
# pip install requests beautifulsoup4
import csv, requests
from bs4 import BeautifulSoup
url = "https://quotes.toscrape.com/"
headers = {"User-Agent": "ResearchBot/1.0 (+https://example.com/bot)"}
res = requests.get(url, headers=headers, timeout=15)
res.raise_for_status()
soup = BeautifulSoup(res.text, "html.parser")
rows = []
for card in soup.select("div.quote"):
rows.append({
"text": card.select_one("span.text").get_text(strip=True),
"author": card.select_one("small.author").get_text(strip=True),
})
with open("quotes.csv", "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=["text", "author"])
writer.writeheader()
writer.writerows(rows)
print(f"extracted {len(rows)} records")
Three details in that snippet are not decoration. The identifying User-Agent tells the site who you are and how to reach you. The timeout stops a hung connection from stalling the run. The raise_for_status() call means a 403 or 503 fails loudly instead of quietly parsing an error page into your dataset.
The same job through a hosted API removes the fetch-layer concerns entirely:
import requests res = requests.post( "https://api.gcrawlai.com/v1/scrape", headers={"Authorization": "Bearer YOUR_API_KEY"}, json={"url": "https://example.com/product/123", "format": "markdown"}, timeout=60, ) data = res.json()
That is the whole trade in one comparison: the first version is free and yours to maintain; the second costs per request and someone else maintains the proxies, the browsers and the retry logic.
Static vs dynamic pages — the fork that decides your cost
Almost every surprise in a scraping budget traces back to this one distinction, and most introductory guides skip it.
A server-rendered page arrives with its content already in the HTML. One HTTP request gets you everything. It is fast, cheap, and parseable with a library that weighs a few hundred kilobytes.
A client-rendered page arrives as a near-empty document plus a JavaScript bundle. The content appears only after the browser executes that bundle and calls back to an API. Fetch it with a plain HTTP client and you get a shell with no data in it — the single most common reason a beginner's scraper returns nothing.
WHAT EACH PAGE TYPE COSTS YOU
| Server-rendered | Client-rendered | |
|---|---|---|
| Tool needed | HTTP client + parser | Headless browser (Playwright, Puppeteer) |
| Memory per page | Kilobytes | Hundreds of megabytes |
| Relative speed | Fast | Roughly an order of magnitude slower |
| Relative cost | Low | Substantially higher on every hosted service |
| Failure mode | Selector no longer matches | Race condition — you read before the data arrives |
The shortcut worth checking first
Before you reach for a browser, open the network tab and look at what the page itself is calling. Client-rendered pages fetch their content from an internal JSON endpoint, and that endpoint is frequently reachable directly. When it is, you skip rendering altogether and get cleaner data than any HTML parse would give you. This one check has saved more scraping budgets than any other optimisation.
The types of web scrapers
By who builds it
- Custom-built. Written from scratch in Python, JavaScript or Go. Complete control, complete maintenance burden. Correct when the target is unusual or the logic is genuinely specific to your business.
- Pre-built / no-code. Point-and-click tools that generate selectors visually. Fast for one-off jobs and non-engineers; they tend to hit a ceiling on pagination, authentication and volume.
- API-based. You send a URL and receive content or fields. The infrastructure problems belong to the vendor. This is the dominant model for teams whose product is the data, not the pipeline.
By where it runs
- Browser extension. Runs inside your session on the page you are viewing. Trivial to start, capped by browser limits and by the fact that your laptop has to stay open.
- Local application or script. Runs on your machine. Full control, bounded by your CPU, RAM and residential bandwidth.
- Cloud. Runs on remote infrastructure on a schedule. Parallelises, survives your laptop closing, and is the only sane option above a few thousand pages.
By extraction method
- Selector-based. Hard-coded CSS or XPath paths. Precise, fast, and brittle — a class rename breaks it.
- Model-based. A model infers which element is the price without being told its path. More resilient to redesigns, more expensive per page, and occasionally wrong in ways a selector never would be.
- Hybrid. Selectors first, model as fallback when they return null. In production this is usually the right answer.
Why scraping gets hard at scale
A hundred pages is a script. A hundred thousand pages a day is a distributed systems problem.
COMMON OBSTACLES AND THE STANDARD RESPONSES
| Obstacle | What you see | Standard response |
|---|---|---|
| Rate limiting | 429 responses, then temporary blocks | Concurrency caps, exponential backoff, request budget per host |
| IP blocking | 403 from one address, fine from another | Proxy rotation; residential IPs only where genuinely needed |
| Fingerprinting | Blocked despite valid headers | Consistent TLS, HTTP/2 and browser signals — mismatches are the tell |
| Interactive challenges | A verification page instead of content | Slow down first; challenges are a symptom of detection upstream |
| Layout drift | Nulls where values used to be | Schema validation on every run, alerting on extraction-rate drops |
| Pagination and infinite scroll | Only the first 20 records | Follow the underlying API offset rather than simulating scroll |
| Geo-variant content | Different prices per country | Explicit geo-targeted requests; treat locale as a field, not a setting |
| Malformed HTML | Parser returns nonsense | Lenient parsers; never parse HTML with regular expressions |
On aggressive evasion
There is a real line between making your traffic well-behaved and actively defeating a site's security controls. Rotating IPs to spread ordinary load sits on one side of it. Systematically circumventing an authentication measure sits on the other, and moves your exposure from contract law to computer misuse law. Know which side a given technique puts you on before you deploy it.
What web scraping is used for
- Price intelligence and MAP monitoring
- The largest commercial use case. Retailers track competitor pricing to set their own; brands monitor resellers for minimum advertised price violations. Requires high frequency and low tolerance for stale data.
- Market and competitive research
- Assortment tracking, catalogue expansion, share-of-shelf, feature comparison. The value comes from breadth across sources rather than depth on any one.
- Training data and retrieval corpora for AI
- The fastest-growing category. Models need text, and retrieval systems need current documents. Covered in detail in the next section.
- Lead generation
- Building prospect lists from directories, marketplaces and company sites. The use case most likely to collide with privacy law — see the legal sections below before you build this.
- Sentiment and brand monitoring
- Reviews, forums and public social posts, aggregated into a signal about how a product or brand is received.
- News and regulatory monitoring
- Watching filings, notices, tenders and press releases for changes that matter. Compliance and legal teams are heavy consumers.
- Alternative data for finance
- Job postings, hiring velocity, app rankings, shipping records and pricing used as leading indicators alongside conventional financial data.
- Real estate and travel aggregation
- Listings, availability and pricing pulled across many providers into a single comparable view.
Scraping for AI: training data, RAG and agents
Data extraction changed shape once large language models arrived. Three distinct needs now sit under one heading, and conflating them causes both technical and legal trouble.
Pre-training corpora
Bulk text at enormous scale, valued for volume and diversity. This is where the sharpest copyright disputes are concentrated, and where the answer varies most by jurisdiction.
RAG and knowledge bases
Retrieval-augmented generation needs a much smaller, much fresher corpus: current documentation, current pricing, current policy. Here the output format matters more than the volume. Clean Markdown with headings preserved chunks far better for embedding than raw HTML full of navigation and cookie banners, which is why "return me clean Markdown" has become a standard requirement rather than a nicety.Agent browsing
An AI agent completing a task needs a page's readable content on demand, in seconds, one URL at a time. The workload profile is the inverse of a crawl: low volume, high latency sensitivity, unpredictable targets.
Practical implication
If the destination is an embedding model, optimise the extractor for clean Markdown and stable heading structure — not for raw HTML fidelity. Boilerplate stripped at extraction time is boilerplate you do not pay to embed, store and retrieve forever.
Is web scraping legal?
Direct answer
Scraping publicly accessible data is generally lawful in most major jurisdictions. Legality does not turn on the act of automation — it turns on what you collect, how you access it, and what you do with it afterwards.
The pattern across recent litigation is reasonably consistent. Courts in the United States have declined to treat the automated collection of public pages as unauthorised computer access, reasoning that data available to any visitor without credentials is not "protected" in the sense anti-hacking statutes contemplate. Disputes have increasingly shifted from computer-misuse claims towards contract and copyright theories instead.
Four questions determine your actual exposure:
| Question | Lower risk | Higher risk |
|---|---|---|
| Is it public? | Visible with no login | Behind authentication or a paywall |
| Is it personal data? | Prices, specs, company facts | Names, emails, profiles, anything identifying a person |
| Is it creative work? | Facts and figures | Full articles, images, reviews, substantial text |
| What's the downstream use? | Internal analysis | Republication, resale, a substitute for the original |
Privacy law is the sharper edge
Under the GDPR, personal data does not lose its protection because it happens to be published. If you scrape names, emails or profiles relating to people in the EU or UK, you need a lawful basis, and the transparency obligations still apply even though you never interacted with the person. This — not copyright — is what most commercial scraping programmes actually stumble over.
robots.txt and terms of service
Neither is a statute. robots.txt is a voluntary protocol, standardised only in 2022 as RFC 9309, and terms of service are a contract whose enforceability against a non-logged-in visitor is contested. Both still matter: they are documentary evidence of the site owner's expressed wishes, and disregarding an explicit disallow makes any later good-faith argument much harder to sustain.
The legal position in India
Most guides on this topic address only US and EU law. If you operate from or collect data about India, three separate regimes apply.
The Digital Personal Data Protection Act, 2023
The DPDP Act governs digital personal data processed in India, and applies extraterritorially where processing relates to offering goods or services to people in India. Its treatment of scraped data is narrower than it is often assumed to be. The Act's exemption covers personal data that the individual has voluntarily made publicly available themselves, or that is made public under a legal obligation. Data that a third party published about someone does not obviously fall inside that carve-out, and neither does data the person shared for one purpose being repurposed for another. Personal data scraped for lead generation should be treated as in-scope until you have specific advice saying otherwise.
The Copyright Act, 1957
Copyright protects the expression on a page, not the facts within it. Extracting the price and specification of a product is materially different from copying the full editorial review that sits beside it. India recognises fair dealing for a defined set of purposes including private study and research — it is a narrower door than the US fair-use doctrine, and commercial redistribution does not fit through it.
The Information Technology Act, 2000
Sections addressing unauthorised access to computer systems are the reason credential-gated scraping is treated so differently from public-page scraping in Indian practice. Public pages sit far from this provision. Anything requiring you to defeat an access control sits much closer to it.
This section is a technical practitioner's summary intended to help you scope a conversation with counsel, not a substitute for one. Rules differ by jurisdiction, by data category and by intended use, and this area is moving quickly.
An ethical scraping checklist
Legality is the floor. These practices keep you above it and, incidentally, keep you unblocked.
- Read
robots.txtand honour it. Where you have a considered reason to depart from it, write that reason down. - Identify yourself. A User-Agent with a contact URL turns a potential block into an email. That trade is almost always worth it.
- Rate-limit deliberately. Stay well below the point where your traffic is noticeable in the target's monitoring. This is the single most effective anti-blocking measure available.
- Cache and never re-fetch what you already have. Most scrapers re-request unchanged pages daily for no reason.
- Prefer the API and the sitemap. Structured sources exist to be used.
- Collect only the fields you need. Data minimisation is a privacy obligation in several regimes and a cost saving in all of them.
- Avoid personal data unless you have a basis. And if you do collect it, apply retention limits from day one.
- Never touch anything behind a login without written permission.
- Scrape off-peak. Overnight in the target's timezone reduces your impact on real users.
- Respond to takedown requests promptly. A quick, cooperative response is worth more than any technical countermeasure.
Build or buy: an honest comparison
| Approach | Best when | Real cost | Watch out for |
|---|---|---|---|
| Open-source libraries Scrapy, BeautifulSoup, Playwright |
You have engineers and the targets are cooperative | Free software, paid engineering time | Maintenance compounds with every target you add |
| Self-hosted framework Scrapy + your own proxies |
High volume, predictable targets, cost pressure | Infrastructure plus a named owner | Proxy and browser management becomes a project of its own |
| Scraping API | You want data, not a pipeline; targets are protected | Per successful request | Credit systems that make real cost hard to predict |
| Managed data service | Very large one-off or ongoing feeds, no in-house team | Highest per record | Lead time and limited flexibility on schema changes |
A reasonable default: prototype with open-source against your real targets. If the fetch layer is where your time is going — proxies, blocks, browser memory — move that layer to an API and keep your own logic for parsing and validation, which is the part that encodes your actual domain knowledge.
Where GcrawlAI fits
GcrawlAI is an open-source web scraping API from Gramosoft, MIT-licensed and available on GitHub. It handles fetching, rendering and retries, and returns clean Markdown or JSON — the format that chunks well for embeddings and RAG pipelines. Self-host it, or use the hosted API and pay per successful request with no credit-multiplier arithmetic.
Glossary
- Crawler (spider)
- A program that discovers pages by following links and building a queue of URLs to visit.
- Parser
A library that converts an HTML string into a navigable tree so elements can be selected programmatically.
Selector
A CSS or XPath expression identifying which element on a page holds a given value.
Headless browser
- A real browser engine driven by code with no visible window, used to execute JavaScript before extraction.
- Proxy
- An intermediary server that issues your request from a different IP address. Datacentre proxies are cheap and easily identified; residential and mobile proxies are costlier and harder to distinguish from ordinary traffic.
- Fingerprinting
Identifying a client from the combination of signals it emits — TLS handshake, HTTP/2 frame ordering, fonts, canvas rendering — rather than from its IP address alone.
- Rate limiting
- A server-side cap on requests per client per interval, usually signalled with HTTP 429.
- Layout drift
- The gradual breakage of selectors as a target site changes its markup. The main ongoing maintenance cost in any scraping system.
- Extraction rate
- The proportion of attempted records that yield complete, schema-valid output. The single most useful health metric for a scraper.
Sources and primary references
| 1. |
RFC 9309 — Robots Exclusion Protocol, IETF, 2022. The first formal standardisation of |
| 2. |
The Digital Personal Data Protection Act, 2023, Ministry of Electronics and IT, Government of India. See Section 3(c)(ii) on personal data made publicly available by the Data Principal. |
| 3. |
GDPR Article 14 — information obligations where personal data is not obtained from the data subject. The provision that applies to scraped personal data. |
| 4. |
Van Buren v. United States, 593 U.S. (2021). Narrowed the Computer Fraud and Abuse Act's "exceeds authorized access" clause. |
| 5. |
The Copyright Act, 1957 (India). Section 52 sets out the fair dealing exceptions. |
| 6. |
Scrapy and Playwright official documentation. |
