Glossary
Structured data: the machine readable layer of a page
Structured data is markup that a site adds so search engines can understand a page, and the same markup gives scrapers clean, labeled fields to read.
The three formats
Sites describe products, articles, events, recipes and organizations using the schema.org vocabulary, written in one of three syntaxes.
| Format | Where it lives | How common |
|---|---|---|
| JSON-LD | A <script type="application/ld+json"> block | The format search engines recommend, and the most common today |
| Microdata | itemscope, itemtype and itemprop attributes on HTML elements | Still widespread on older templates |
| RDFa | vocab, typeof and property attributes | Less common on commercial sites |
Pages may also carry Open Graph meta tags (for link previews), which overlap with structured data and are worth reading as a fallback.
Why scrapers should start here
Site owners maintain structured data carefully because it affects how they appear in search. That makes it more stable than visual markup: a redesign changes class names and layout but usually keeps the JSON-LD intact. A product block typically gives name, brand, SKU, GTIN, price, currency and availability with clear labels, which saves you from guessing which span holds the price. For price monitoring, the GTIN field alone solves much of the product matching problem.
Reading JSON-LD
import json
import bs4
def ld_items(markup):
soup = bs4.BeautifulSoup(markup, "html.parser")
for tag in soup.find_all("script", type="application/ld+json"):
try:
blob = json.loads(tag.string or "")
except ValueError:
continue # some sites ship broken JSON-LD
nodes = blob if isinstance(blob, list) else blob.get("@graph", [blob])
for node in nodes:
yield node.get("@type"), node
Watch for a few quirks: @type can be a list, offers may be a single object or an array, and prices sometimes arrive as strings with thousands separators. Normalize before storing. Libraries exist that extract all three formats at once, which is handy when you crawl many different sites. The parser above uses Beautiful Soup.
When structured data is missing or wrong
Not every page has it, and some have stale values (a price in JSON-LD that differs from the visible one after a sale started). Cross check a sample against the rendered page, and fall back to CSS selectors or a JSON endpoint when needed. Some sites add structured data only through JavaScript, so a plain HTTP fetch sees nothing and you need rendering.
Other places to look
Besides JSON-LD blocks, check the meta tags in the head (Open Graph price and image tags), any data- attributes on the add to cart button, and inline state objects that frameworks such as Next.js or Nuxt embed for hydration. These often hold the full product record the page was built from, including variants and stock per size.
Getting to the page first
Structured data only helps once you have the HTML. On protected sites, the first response may be a challenge page instead of the product. Detect that (no JSON-LD, a challenge script, a 403 or 503 status), solve the challenge, and fetch again. For a Cloudflare Challenge task you receive a clearance cookie tied to your proxy, typically under 10 seconds; reuse it for the following product pages in the same session.
Common questions
What is the most common structured data format?
JSON-LD, a script block containing schema.org data in JSON. Search engines recommend it, so most modern sites use it.
Is structured data more reliable than CSS selectors?
Usually, because site owners keep it stable for search engines even when the visual design changes.
Can JSON-LD prices differ from the visible price?
Yes, occasionally, for example right after a sale starts. Check a sample against the rendered page.
Why do I see no JSON-LD in the downloaded HTML?
The site may inject it with JavaScript, or you received a challenge page instead of the real page.
What vocabulary does structured data use?
Almost always schema.org, which defines types such as Product, Offer, Article and Organization.
Keep reading
- Data extractionData extraction turns raw HTML or JSON into clean, typed records with a fixed schema that downstream tools can trust.
- HTML parsingHTML parsing turns markup into a tree your code can query, and tolerant parsers rebuild broken pages the same way browsers do.
- Beautiful SoupThe forgiving Python library for parsing HTML and XML into a tree you can search by tag, attribute or CSS selector.
- How do I read JSON from a response in Python?Call response.json() after checking status and content type, and pull JSON embedded in HTML with a parser.