Skip to content

Parser

A program that parses structured text — HTML, JSON, YAML, Markdown — and converts it into convenient structures for work.

Example

from bs4 import BeautifulSoup

soup = BeautifulSoup(html, "html.parser")
title = soup.find("h1").text

Why Needed

Data often arrives in a 'raw' form: a string of HTML or JSON. A parser converts it into objects from which values can be easily extracted.

Parser vs regex

A parser understands the structure of a document, regex does not. For HTML and JSON, a parser is always better: it is more reliable and does not break from minor formatting changes.

See also

← All terms