Read a page’s head metadata¶
A page’s <head> holds the facts a link preview or an index wants: the title, the description, the canonical URL, and
the OpenGraph card. Read them off a parsed document with select_one() and
attr(), and let structured_data() gather the OpenGraph block.
Read the OpenGraph card¶
The OpenGraph and Twitter-card tags come off structured_data(), which reads them into a dict
in one walk rather than a selector per property, the metadata_parser and opengraph use case:
doc = turbohtml.parse(
'<head><meta property="og:title" content="Widget">'
'<meta property="og:image" content="https://shop.example/w.png">'
'<meta name="twitter:card" content="summary"></head>'
)
card = doc.structured_data().opengraph
print(card["og:title"], card["og:image"])
print(card["twitter:card"])
Widget https://shop.example/w.png
summary
Read the title, the description, the canonical link, and the card in one parse, no per-field library. For the full set of embedded formats – JSON-LD, Microdata, RDFa – see Extract structured data.