Web scraping

Also known as: web data extraction

On this page 7

Web scraping, also called web data extraction, is the automated retrieval of web pages and the conversion of their content into structured, machine-readable records. In data engineering, it serves as a data ingestion method of last resort or convenience: it collects information that a website displays to people but does not offer through an API, bulk download or data feed.

A scraper behaves like a very fast, very literal browser. It requests a page, locates the elements that hold the wanted values, extracts them and writes them to a table, file or data pipeline. The technique is simple in principle but fragile in practice, because it depends on page layouts that the site owner can change at any time and on legal and ethical limits that vary by jurisdiction.

How a web scraper extracts data

A web scraper works through a fetch, parse, extract and store cycle that repeats for every target page. The fetch step sends an HTTP request; the parse step builds a document tree from the returned HTML; the extract step applies CSS selectors or XPath expressions to pick out values; the store step normalizes and saves them.

Larger projects add a crawler that discovers new URLs by following links or reading sitemaps, a scheduler that controls request frequency, and a validation layer that rejects records with missing or malformed fields. The table below lists the main components and their role.

ComponentFunctionTypical implementation
URL frontierHolds the queue of pages to visitDatabase table or message queue
FetcherDownloads pages while respecting rate limitsHTTP client with retries and timeouts
RendererExecutes JavaScript for dynamic pagesHeadless browser such as Chromium
Parser and extractorLocates and reads the target fieldsCSS selectors, XPath, regular expressions
ValidatorChecks types, ranges and completenessSchema rules or data contracts
Storage writerLoads records into the destinationFiles in a data lake or warehouse tables
Components of a production scraping system

Static pages, dynamic pages and hidden APIs

The difficulty of web scraping depends mostly on how the target page delivers its content. Server-rendered pages include the data in the initial HTML, while modern single-page applications load it later through JavaScript calls to internal endpoints.

Page typeRecommended approachCost and reliability
Static HTMLPlain HTTP requests and an HTML parserFast, cheap, breaks when markup changes
JavaScript-renderedHeadless browser automationSlow, resource-heavy, handles complex pages
Internal JSON endpointCall the endpoint the page itself usesEfficient and stable, but undocumented
Paginated or infinite scrollIterate page parameters or simulate scrollingRequires careful stop conditions
Scraping approaches by page type

Experienced engineers inspect network traffic first. When a page fetches its data as JSON from an internal endpoint, reading that response directly is usually faster and more robust than parsing rendered HTML, although the endpoint may change without notice because it was never meant as a public interface.

Web scraping compared with other ingestion methods

Web scraping is one of several ways to bring external data into a platform, and it is rarely the first choice when an alternative exists. Official channels provide stable schemas, documented limits and clear permission, which scraping lacks.

MethodStabilityMain drawback
Web scrapingLow, tied to page layoutBreakage, legal uncertainty, blocking
Public or partner APIHigh, versioned contractRate limits, fees, limited fields
Bulk download or open data portalHigh for periodic snapshotsLower freshness
Managed connectorHigh, maintained by a vendorLicense cost and vendor dependency
Data marketplace purchaseHigh, curatedCost and less control over collection
Scraping versus alternative data sources

Within an ETL or ELT architecture, scraped output is usually landed raw first, for example in the bronze layer of a medallion architecture, and then cleaned downstream. Keeping the raw HTML or JSON allows the team to re-extract fields after a parser fix without fetching pages again.

The legality of web scraping is not settled by a single rule; it depends on the data collected, the method used, the site terms and the jurisdiction. Courts in different countries have reached different conclusions, and the area continues to evolve.

  • Personal data falls under privacy law such as the GDPR in the European Union, which requires a lawful basis even when the information is publicly visible.
  • Copyright and database rights can protect the selection or arrangement of content, especially in the EU under the sui generis database right.
  • Terms of service may prohibit automated access, and breaching them can create contractual liability.
  • Circumventing technical barriers, such as logins or access controls, carries considerably higher legal risk than reading openly accessible pages.

Ethical practice adds operational courtesy: honoring the robots.txt file, identifying the scraper with a descriptive user agent, keeping request rates low and avoiding collection of data that is not needed. Teams that handle sensitive categories usually obtain legal review before production use.

Operational risks and maintenance

The ongoing cost of web scraping lies mainly in maintenance rather than initial development. A scraper that took a day to write can require repeated fixes as target sites redesign pages, add bot detection or change URL patterns.

SymptomLikely causeMitigation
Fields suddenly emptyMarkup or class names changedSelector tests and alerting on null rates
HTTP 429 or 403 responsesRate limiting or blockingSlower crawl, backoff, permission request
Duplicate recordsPagination overlap or retriesNatural keys and idempotent loads
Wrong values in correct fieldsLayout shift moved elementsRange checks and schema validation
Missing new itemsCrawler cannot reach new URLsSitemap reading and link discovery audits
Common failure symptoms and their fixes

Mature teams treat scrapers like any other production source: they apply monitoring, data contracts and lineage tracking, and they record when and from which URL each record was collected so that downstream users can judge freshness and provenance.

Stripped to the essentials

Web scraping means letting a program read websites for you and copy specific details into a spreadsheet. Instead of a person opening hundreds of product pages and typing prices by hand, the program visits each page and writes the prices down in seconds.

The catch is that websites are built for human eyes, not for programs. When a site changes its design, the program can lose track of where the information sits. There are also rules about what may be collected, so careful scraping respects both the law and the site owner.

Where it is applied

A mid-sized consumer electronics retailer wants to track competitor prices for about 4,000 products across six online stores, none of which offers a public price feed. The data engineering team builds a scraper that visits each product page once per night, at a rate of roughly one request every two seconds per site, and extracts the price, availability and shipping cost.

Raw responses land in cloud storage, and a nightly job parses them into a warehouse table keyed by product code and date. Validation rules flag prices that move more than 50 percent overnight, which usually indicates a parsing error rather than a real change. When one competitor redesigns its site, the null-rate alert fires within a day and the team updates the selectors.

The pricing team uses the resulting dataset to adjust prices on high-volume items, and the retailer gains a consistent daily view of the market that previously required hours of manual checking each week.