Web Scraping — Automated Web Data Collection

Measurement
Introduced by
Early internet practitioners; systematised in research contexts from the late 1990s onward
Year
Late 1990s–2000s
Type
Automated digital data collection technique
Family
Data collection

What does it do?

Web scraping is a computational data collection technique in which software retrieves web pages and extracts structured or semi-structured content from them automatically.

It is used in social science, computational linguistics, economics and information science to assemble datasets from publicly accessible sources such as news archives, social media platforms, government portals and online marketplaces. It is most useful where the same information would be too slow or too large to copy by hand.

The intuition behind the method

Think of web scraping as a script that visits web pages much as a researcher would, reads their HTML, picks out the pieces needed (prices, article titles, post timestamps, user reviews) and writes them into a spreadsheet or database. The difference is scale: a single run can process thousands to millions of records. The method depends on the fact that most web content is marked up with HTML tags and CSS classes, which give the script anchors for locating each field, although these anchors can change when a site is redesigned.

History

Web scraping is the automated extraction of content from web pages, and it has developed alongside the web itself. Practitioner accounts such as Mitchell (2018) cover the main tools used in the field, from HTTP and HTML parsing libraries to browser automation for pages whose content is rendered by JavaScript.

When to use it

Choose web scraping when the data needed is spread across many publicly accessible web pages, is not offered through an official API or a downloadable dataset, and must be collected at a scale or frequency that manual copying cannot achieve. Typical uses include news corpora, social media posts, product listings, job advertisements and policy documents, where the target content is machine-readable HTML. Do not use it when the platform offers an API that covers the required data, since APIs are generally more stable and have clearer terms of use. Avoid it when the site's terms prohibit automated access, when the data sits behind a login that was not obtained for research purposes, or when personal information is involved without ethics review and a lawful basis for processing.

Limitations and considerations

  • Legality and ethics vary by case: terms of service, copyright and data protection rules such as the GDPR can restrict collection, so permission must be assessed for each target site.
  • Extraction rules are tied to page markup; a redesign or a renamed CSS class can silently break them, so collections need ongoing monitoring and maintenance.
  • Anti-bot measures such as rate limiting or blocking can interrupt collection and leave the sample incomplete in ways that are hard to detect after the fact.
  • Sites that render content with JavaScript or require login add technical steps (headless browsers, session handling) that increase failure rates and maintenance effort.
  • Pages within the same site may differ in template, language or encoding, so extraction logic often needs exceptions that must be documented.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Collects records at a scale that manual coding cannot match; a single run can gather very large datasets, in some cases millions of records.
  • Preserves content as published, including wording, formatting and any timestamps shown on the page, which can be stored alongside the extracted fields.
  • Can be scheduled to run repeatedly, so the same extraction rules support panel-style or continuously updated collections.
  • Once extraction rules are written and checked, each additional record costs little, because one script handles every page that shares the same template.
  • Applies to any publicly accessible page whose markup can be parsed, regardless of domain or language.

Applications

  • Assembling longitudinal corpora of news articles or political speeches for computational text analysis.
  • Tracking price dynamics on e-commerce platforms for economic or consumer behavior research.
  • Monitoring social media platforms (where API access is unavailable or limited) to study public discourse, misinformation, or health communication.
  • Collecting job postings at scale to analyse labor market trends and skill demand.
  • Compiling government or parliamentary records, legislative texts, and court decisions for legal and policy research.
  • Building training and evaluation datasets for natural language processing and machine learning models.
  • Collecting drug-interaction and adverse-effect data from online sources, then filtering it by local availability, to build a pharmacology decision-support system.

How it works

How it works

1

The researcher specifies the target sites or URL patterns, the exact fields to be collected, and whether the content is static HTML or loaded dynamically by JavaScript. Before any request is sent, the site's robots.txt file and terms of service should be reviewed as ethical and contractual signals; compliance with them does not by itself establish that collection is lawful.

2

A script, often written in Python with libraries such as Requests, Scrapy or Selenium, sends HTTP GET requests to the target URLs and receives the raw HTML or JSON responses. If the content is generated by JavaScript after the page loads, a headless browser such as Playwright or Selenium is needed so that the page can render before its content is captured.

3

The raw response is converted into a navigable document tree using a parser such as BeautifulSoup or lxml. The script then locates the nodes that hold the target data by tag name, CSS class or XPath expression. Extraction rules written against these selectors are only as stable as the page's underlying markup.

4

The matched elements are traversed and their text, attributes or links are converted into structured records, one row per item. For multi-page collections the script follows pagination links or generates URL patterns, so that every relevant page contributes its records to the dataset.

5

Records are written to a CSV or JSON file for small collections, or to a relational or document database such as PostgreSQL or MongoDB for large or ongoing ones. The source URL and collection timestamp should be stored with each record so that the origin of every observation can be traced later.

6

The assembled dataset is checked for missing fields, duplicate records, encoding problems and structural irregularities. A sample of records should be compared manually with the source pages to confirm that the extraction rules are correct. If the target site changes its layout, the scraper must be updated and the resulting break in the series documented.

Common pitfalls

  • Disregarding robots.txt and terms of service. Pages the site owner has disallowed can lead to blocked IP addresses, complaints from the operator and possible legal exposure.
  • Treating public profiles as non-sensitive. Names, locations or health-related posts that are publicly visible still carry re-identification risk when aggregated, and many research contexts require ethics board review.
  • Sending requests too quickly. High request rates can burden small or community-run servers, so crawl delays and respect for rate-limit responses should be built in from the start.
  • Assuming the sample is representative. Scraped data covers only what is published and reachable; paywalls, platform ranking algorithms and geographic restrictions create systematic gaps that should be stated in the analysis.
  • Losing provenance. Without recording the URL, scrape date and scraper version, a dataset cannot be reproduced or audited, and a re-scrape after a site change cannot be distinguished from the original collection.

Frequently asked questions

Is web scraping legal?

Legality depends on jurisdiction, the specific data collected, the target site's terms of service, and any applicable data protection law. That a page is publicly visible does not by itself make its reuse lawful. In the United States, the appellate decision in hiQ v. LinkedIn (2022) concerned the Computer Fraud and Abuse Act; it has been read as limiting liability under that statute for public data, but it does not establish general permission to scrape and does not override contract terms or the GDPR (EU) or equivalent laws, which impose strict limits on personal data. Review the site's robots.txt and terms of service, seek advice from your institution's legal office for any sensitive case, and obtain ethics board approval when personal data is involved.

When should I use an API instead of scraping?

Whenever an official API covers your data needs, use it. APIs are explicitly designed for programmatic access, are legally clear, offer structured data with defined schemas, and are far more stable than HTML-based scrapers. Web scraping should be reserved for cases where no adequate API exists or where the API's rate limits or data scope do not meet research requirements.

How do I handle JavaScript-rendered content?

Standard HTTP request libraries fetch the raw HTML before JavaScript executes, which means dynamically loaded content (rendered by frameworks such as React or Vue) is invisible to them. For such sites, use a headless browser tool — Playwright or Selenium — which launches a real browser engine, waits for the page to fully render, and then exposes the complete DOM for parsing.

How do I ensure my scraped dataset is reproducible?

Record the full URL, the exact scrape timestamp, and the scraper version for every record. Archive a sample of raw HTML responses. Version-control your scraping code and document any changes to extraction logic. If the source site changes structure and you re-scrape, treat it as a new data collection wave and document the discontinuity.

What ethical issues arise beyond legal compliance?

Even when scraping is technically lawful, researchers should consider whether data subjects have a reasonable expectation that their content will be used for research, whether aggregation of public posts could re-identify individuals, whether publication of scraped quotes could harm participants, and whether server load from scraping imposes costs on small or community-run sites. Follow the ACM or AoIR ethical guidelines for internet research.

Related methods

Sources

  1. Mitchell, R. (2018). Web Scraping with Python: Collecting More Data from the Modern Web (2nd ed.). O'Reilly Media.

    ISBN: 978-1491985571
  2. Web scraping. Wikipedia.

    Open publication reference
  3. Intelligent-and-Fuzzy-Systems, p. 264