##############
From extruct
##############
.. package-meta:: extruct scrapinghub/extruct
`extruct
' ) data = extruct.extract(html, syntaxes=["json-ld", "opengraph", "microdata"]) print(data["json-ld"]) print(data["opengraph"]) print(data["microdata"]) After, one walk returns a typed record whose fields you read by attribute: .. testcode:: from turbohtml import parse doc = parse( '
' '
' ) data = doc.structured_data() print(data.json_ld) print(data.opengraph) offer = data.microdata[0] print(offer.type, offer.properties) .. testoutput:: [{'@type': 'Product'}] {'og:title': 'Widget'} https://schema.org/Offer {'price': ['9.99']} The per-format helpers return the same plain objects, holding no reference back into the tree, so you can keep them after the document is gone: .. testcode:: doc = parse('') print(doc.json_ld()) .. testoutput:: [{'@type': 'Article', 'name': 'Hi'}] ********************** Gotchas and pitfalls ********************** - The OpenGraph result is a flat ``{key: value}`` mapping, not ``extruct``'s list of namespaced property tuples, and ``og:`` and ``twitter:`` tags share the one mapping because pages mix the ``property`` and ``name`` attributes freely. When a key repeats, the last occurrence wins; read :meth:`~turbohtml.Document.json_ld` when you need every occurrence of a repeated key. - :attr:`~turbohtml.StructuredData.microformats` is a later phase: :meth:`~turbohtml.Document.structured_data` returns it as an empty list today, so code that reads it will not break when it lands, but the values are not there yet. RDFa and Dublin Core are populated, in :attr:`~turbohtml.StructuredData.rdfa` and :attr:`~turbohtml.StructuredData.dublin_core`. - RDFa ``property`` keys and ``typeof`` IRIs are expanded against the in-scope ``@vocab``/``@prefix`` (with the RDFa 1.1 initial context seeding the common prefixes); an undeclared prefix or a bare term with no vocabulary in scope stays verbatim. Pass ``base_url=`` to :meth:`~turbohtml.Document.rdfa` to absolutize the ``resource``/``href``/``src`` IRIs. - A JSON-LD block whose body is not valid JSON is skipped rather than raising, matching ``extruct``'s default error handling; ``extruct``'s ``errors="strict"`` mode has no turbohtml equivalent. Pass the raw ``