Start free

How to scrape Wikipedia

Extract Wikipedia article title, summary, infobox key-values, section headings, references count and last-edited date as typed, schema-validated JSON.

Site:
en.wikipedia.org
Difficulty:
Easy
Rendering:
Static HTML
Anti-bot:
None in practice on article pages, Server-side rendered HTML, no JS or anti-bot challenge, Polite-crawler rate expectations (honor Crawl-delay and back off on 429)

What you can extract from Wikipedia

These are the fields teams most often pull from en.wikipedia.org, and why a hand-written selector for each one tends to break over time.

Field Type Why selectors break
title string The article title lives in the h1#firstHeading element, but it is rendered with nested span markup for italics, superscripts and disambiguation parentheticals, so a naive selector grabs stray spans or duplicated text instead of the clean canonical title.
summary string The lead summary has no dedicated container; it is simply the first one to three p tags before the first h2, often preceded by hatnotes, coordinate boxes and the infobox, so any nth-child selector silently captures a disambiguation note or an empty paragraph instead of the real intro.
infobox object Infobox rows use table.infobox with th/td pairs, but the class suffix and row layout differ per template (infobox vcard, infobox biography, geography boxes), so a selector tuned to one article returns nulls or misaligned label-value pairs on the next.
section_headings array Section titles sit inside span.mw-headline within h2 and h3, and the surrounding edit-section links and anchor spans mean a bare h2 selector pulls in bracketed [edit] text and citation needed markers along with the heading.
references_count number References render as li elements under ol.references, but cite-error placeholders, named-reference reuse and grouped footnote lists inflate or deflate a raw li count, so the visible numbered total rarely matches a simple length query.
last_edited string The last-modified date appears only in the footer li#footer-info-lastmod as free prose like 'This page was last edited on...', so a selector must parse a localized sentence rather than read a clean machine date attribute.

The schema-first approach

Instead of maintaining selectors, you hand Extracto a JSON schema describing the shape you want. Here is a schema that works for Wikipedia:

{
  "title": "string",
  "summary": "string",
  "infobox": "object",
  "section_headings": "array",
  "references_count": "number",
  "last_edited": "string"
}
  1. 1

    Describe the Wikipedia fields you want

    Write a small JSON schema listing the fields to pull from en.wikipedia.org (for example title, summary, infobox). No CSS selectors or XPath needed.

  2. 2

    Send the URL and schema to Extracto

    POST the Wikipedia page URL and your schema to the Extracto API. Extracto renders the page in a real browser, handling the HTML automatically.

  3. 3

    Get schema-validated JSON back

    Extracto returns JSON that matches your schema exactly, validated before it leaves the API, so your pipeline never receives broken or partial data.

Common pitfalls when scraping Wikipedia

Is it legal to scrape Wikipedia?

Wikipedia article prose and the structured data within it are published under the Creative Commons Attribution-ShareAlike (CC BY-SA) license, with some media under separate terms, so reuse is broadly permitted as long as you attribute Wikipedia and the contributing authors and preserve the share-alike condition. The robots.txt at en.wikipedia.org does NOT disallow regular /wiki/ article pages, but it explicitly blocks site-mirroring tools (HTTrack, wget, WebReaper and similar) and the /w/ and /api/ internal paths, and the file warns that "irresponsible" high-volume crawlers may be blocked. The Wikimedia Foundation Terms of Use and the official robots policy ask that bulk reusers prefer the public dumps and the REST API over scraping rendered HTML, identify themselves with a descriptive User-Agent, and keep request rates modest. Extracting a handful of article pages at a polite cadence for analysis or enrichment is well within accepted use; mass mirroring of the site is not. As of 2026 the canonical large-scale path remains the Wikimedia dumps, so treat live extraction as a targeted, low-volume complement, not a substitute.

Extracto follows robots.txt by default and rate-limits politely. You are responsible for compliance with Wikipedia's terms and applicable law (GDPR, CCPA) in your use case.

Scraping Wikipedia: FAQ

Is scraping Wikipedia articles legal?
Yes for normal, polite use. Article text and the structured data inside it are CC BY-SA licensed, so you may reuse and republish it as long as you attribute Wikipedia and its authors and keep the share-alike terms. The robots.txt allows /wiki/ article pages but blocks site-mirroring tools, and the Wikimedia Terms of Use ask bulk reusers to prefer the dumps and REST API. Keep volume modest and identify your client.
Should I scrape the rendered page or use the Wikimedia API?
For one-off or low-volume needs, pulling a single article URL through Extracto gives you typed JSON immediately with no token or endpoint setup. For large corpora the official Wikimedia REST API and the periodic database dumps are the intended path and are far kinder to the servers. A good rule as of 2026: targeted enrichment over live pages, bulk work over dumps.
Why does the infobox come back with different fields on different articles?
Because the infobox is not one fixed template. A programming language box exposes paradigm, designer and stable release, a person box exposes born, died and occupation, and a country box exposes capital and population. Extracto models the infobox as an open object, returns whatever label-value pairs the page actually carries, and writes null for any field your schema asked for that the article does not have.
Can Extracto get the references count and last-edited date reliably?
Yes. Extracto reads the footer line that states when the page was last edited and normalizes it into your schema field, and it counts the citations rather than blindly counting list items, so reused named references and grouped footnotes do not silently distort the total. If a field genuinely is not present on a given article, it returns null instead of guessing a number.
Does Wikipedia render with JavaScript or use anti-bot challenges?
No. Article pages are server-side rendered static HTML, so the title, summary, infobox, headings and references are all present in the initial response with no client-side hydration and no Cloudflare or DataDome style challenge. That is why Wikipedia is one of the easiest targets to extract cleanly, and why the main discipline here is being a polite, low-rate, well-identified client rather than handling rendering.