Data parsing is the process of extracting structured, usable information from raw scraped content, like HTML, JSON, or XML, and converting it into a clean format such as a spreadsheet or database record. Parsing is the step that turns a raw scraped webpage into actual usable data.

Common Parsing Approaches

  • HTML parsing libraries (like BeautifulSoup or Cheerio), which navigate a page's DOM structure to extract specific elements
  • CSS selector or XPath queries, which target elements by their tags, attributes, or position in the document tree

Parsing Malformed HTML

Real pages often contain invalid markup, and parsers don't repair it the same way. Beautiful Soup's docs show the input <a></p> becoming <a></a> in Python's html.parser, <html><body><a></a></body></html> in lxml, and <html><head></head><body><a><p></p></a></body></html> in html5lib, which parses like a browser. The docs recommend naming the parser explicitly so code gives the same results on every machine.

Parsing JSON

JSON responses are parsed straight into objects instead of searched as markup. In JavaScript, JSON.parse() builds the value a JSON string describes and throws a SyntaxError if the string isn't valid JSON, for example when it has a trailing comma or single-quoted strings.