# Data Parsing: What It Is, With a Real Example

> Data parsing turns raw input such as HTML into typed records. A real example: 34,167 characters of HTML parsed into 30 records in Python on 20 November 2026.

[Home](https://quanticdata.io/) / [Blog](https://quanticdata.io/blog/) / Data Parsing: What It Is, With a Real Example

# Data parsing: what it is, how a parser works, and a real example in Python

Web scraping · Nov 20, 2026 · 7 min read · By [Aldo Morese](https://quanticdata.io/about/), founder of QuanticData

![Data parsing in three stages on a live page on 20 November 2026: 34,167 characters of raw HTML are parsed into a tree and read with CSS selectors into 30 records, then typed so that "376 points" becomes the integer 376 and "241 comments" becomes 241; the card shows one typed record with rank, points, comments and posted time.](https://quanticdata.io/blog/data-parsing/hero.webp?v=20261120h)

On this page

- [How a data parser works](https://quanticdata.io/blog/data-parsing/#how-a-data-parser-works)
- [Data parsing techniques](https://quanticdata.io/blog/data-parsing/#data-parsing-techniques)
- [A data parsing example in Python](https://quanticdata.io/blog/data-parsing/#a-data-parsing-example-in-python)
- [Raw, parsed, typed: the output](https://quanticdata.io/blog/data-parsing/#raw-parsed-typed-the-output)
- [Parsing on your side or on the server](https://quanticdata.io/blog/data-parsing/#parsing-on-your-side-or-on-the-server)
- [What a data parsing error means](https://quanticdata.io/blog/data-parsing/#what-a-data-parsing-error-means)
- [Data parsing tools](https://quanticdata.io/blog/data-parsing/#data-parsing-tools)

Data parsing is the process of reading raw input, such as an HTML page, a log line, a CSV file or a PDF, and converting it into structured records that a program can use, typically JSON, rows or objects. A parser splits the input into parts, maps them to named fields and converts text into proper types such as numbers and dates.

**Run it on the free credit.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-lead&utm_content=data-parsing) · [Explore Web Scraping API](https://quanticdata.io/web-scraping-api/)

Definitions are easy to find. Here is the process on a real page instead: on 20 November 2026 we fetched a live web page, parsed 34,167 characters of HTML into 30 records with Python, typed the strings into numbers, and then ran the same parse server-side in one request. All output below is from that run.

## How a data parser works

Every parser, from a JSON reader to a compiler, does the same three things.

1. **Tokenise.** Split the input into meaningful pieces: tags and text in HTML, fields in a CSV line, words and numbers in a log line.
2. **Build structure.** Arrange the pieces according to the format's rules. An HTML parser builds a tree of elements; a JSON parser builds objects and arrays.
3. **Map and type.** Pick the parts you need, give them names, and convert them: "376 points" becomes the integer 376, a date string becomes a timestamp.

The first two steps are generic and come from a library. The third is specific to your source and is where most parsing code lives, and where it breaks.

## Data parsing techniques

| Technique | Good for | Breaks when |
| --- | --- | --- |
| Format parsers (json, csv, an HTML parser) | Input that already follows a standard format | The input is malformed or the format is wrong |
| CSS selectors and XPath on an HTML tree | Web pages with stable markup | The site renames a class or moves a block |
| Regular expressions | Short, predictable strings such as prices, counts, dates | The pattern varies more than expected |
| Grammar-based parsers | Languages and query syntax | The input does not fit the grammar |
| Machine learning and LLMs | Free text and documents with varying layouts | Confidence is low and nobody checks the output |

Real jobs combine them. The example below uses an HTML parser for structure, CSS selectors to find fields and regular expressions to type them.

## A data parsing example in Python

The input is the Hacker News front page, a public page whose markup is simple and stable. The script gets the raw HTML through our [Web Scraping API](https://quanticdata.io/web-scraping-api/), then parses it with Beautiful Soup and the lxml parser.

```python
import os, re, sys, json, requests
from bs4 import BeautifulSoup
sys.stdout.reconfigure(encoding="utf-8")

API = "https://api.quanticdata.io/v1/scrape"
headers = {"Authorization": f"Bearer {os.environ['QUANTICDATA_API_KEY']}"}
URL = "https://news.ycombinator.com/"

# 1. Get the raw input: the HTML of the page, as a string
html = requests.post(API, headers=headers, timeout=120,
                     json={"url": URL, "format": "html"}).json()["payload"]["content"]
print(f"raw input: {len(html):,} characters of HTML")

# 2. Parse the HTML into a tree, then walk it with CSS selectors
soup = BeautifulSoup(html, "lxml")
stories = []
for row in soup.select("tr.athing"):
    link = row.select_one(".titleline > a")
    sub = row.find_next_sibling("tr").select_one(".subtext")
    score = sub.select_one(".score")
    age = sub.select_one(".age")
    comments = sub.find_all("a")[-1].get_text(" ", strip=True)
    stories.append({
        "rank": row.select_one(".rank").get_text(),
        "title": link.get_text(),
        "url": link["href"],
        "points": score.get_text() if score else None,
        "posted": age["title"] if age else None,
        "comments": comments,
    })
print(f"parsed: {len(stories)} stories\n", json.dumps(stories[2], indent=2))

# 3. Type the strings: '1.' -> 1, '245 points' -> 245, '87\xa0comments' -> 87, 'discuss' -> 0
def to_int(text):
    m = re.search(r"\d+", text or "")
    return int(m.group()) if m else 0

for s in stories:
    s["rank"] = to_int(s["rank"])
    s["points"] = to_int(s["points"])
    s["comments"] = to_int(s["comments"])
    s["posted"] = s["posted"].split()[0] if s["posted"] else None   # ISO time, epoch dropped
print("typed:", json.dumps(stories[2]))

top = sorted(stories, key=lambda s: s["comments"], reverse=True)[:3]
print("most discussed:", [(s["rank"], s["points"], s["comments"]) for s in top])

# 4. The same parse, done server-side: selectors and type functions in the request
r = requests.post(API, headers=headers, timeout=120, json={
    "url": URL,
    "extract": {
        "titles": {"selector": ".titleline > a", "all": True},
        "points": {"selector": ".score", "all": True, "fns": ["amount_from_string"]},
    },
}).json()["payload"]
data = r["data"]
print("server-side:", len(data["titles"]), "titles,", len(data["points"]), "scores, third:",
      data["titles"][2], "/", data["points"][2], type(data["points"][2]).__name__)
```

**Try it on your own targets.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-inline&utm_content=data-parsing) · [Explore Web Scraping API](https://quanticdata.io/web-scraping-api/)

## Raw, parsed, typed: the output

The output of the run at 16:39 CET on 20 November 2026, unedited:

```
raw input: 34,167 characters of HTML
parsed: 30 stories
 {
  "rank": "3.",
  "title": "Frostbite: A new CPU architecture discovered, designed and verified by AI",
  "url": "https://architectlabs.com/blog/frostbite",
  "points": "376 points",
  "posted": "2026-11-20T10:01:41",
  "comments": "241\u00a0comments"
}
typed: {"rank": 3, "title": "Frostbite: A new CPU architecture discovered, designed and verified by AI", "url": "https://architectlabs.com/blog/frostbite", "points": 376, "posted": "2026-11-20T10:01:41", "comments": 241}
most discussed: [(1, 579, 318), (25, 318, 305), (10, 327, 276)]
server-side: 30 titles, 30 scores, third: Frostbite: A new CPU architecture discovered, designed and verified by AI / 376 int
```

Look at the parsed record before typing. Every value is still a string, and two of them hide traps. The rank is "3." with a trailing dot. The comment count is "241\u00a0comments": the space is a non-breaking space (U+00A0), which a parser splitting on ordinary spaces would miss. The posted time is read from an attribute of the age element rather than from the visible relative age ("hours ago"), because the attribute holds a full ISO timestamp.

After typing, the record can be sorted and summed. The three most discussed stories were ranks 1, 25 and 10, with 318, 305 and 276 comments. A story ranked 25th had almost as many comments as the first: a fact you cannot get from the strings.

## Parsing on your side or on the server

Step 4 sends the selectors with the request. The API fetches the page, applies them and returns the fields, and the `amount_from_string` function returns the score as an integer (the output says `376 int`). Both routes returned 30 records.

|  | Parse locally (steps 1 to 3) | Parse server-side (step 4) |
| --- | --- | --- |
| What comes back | The whole page, 34,167 characters | Only the fields you asked for |
| Control | Any Python logic, any library | Selectors plus a list of transform functions |
| Best for | Complex pages, custom rules, debugging | Many pages with the same layout, agents and no-code tools |
| Cost on our API | $0.0015 per successful page either way |  |

For sources we already parse every day, a collector returns typed rows directly: see our [Hacker News collector](https://quanticdata.io/collectors/hacker-news-api/).

## What a data parsing error means

"Data parsing error" is one of the most searched variants of the term. It means the input did not match what the parser expected, so it could not build the structure. Common causes:

- **Wrong format.** A JSON parser receives an HTML error page, often because the request was blocked or redirected. Check the status code and the first characters before parsing.
- **Encoding.** Bytes decoded with the wrong character set, so "Weiß" turns into garbage and a pattern no longer matches.
- **Changed layout.** A selector that worked yesterday finds nothing today. Fail loudly on empty fields rather than writing nulls into your data.
- **Unexpected values.** "discuss" where a number was expected, a non-breaking space, a thousands separator. Type conversion functions must handle them, as `to_int` does above.
- **A version the parser does not support.** Some apps report a parsing error when a file was written by a newer version than the reader understands.

## Data parsing tools

| Input | Python tool |
| --- | --- |
| HTML | Beautiful Soup with lxml, or lxml directly with XPath (see the [Beautiful Soup documentation](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)) |
| JSON | The standard `json` module, or `response.json()` in requests |
| CSV and spreadsheets | `csv`, or pandas `read_csv` and `read_excel` |
| Text patterns | `re` |
| Web pages at scale | A scraping API that returns Markdown, HTML or extracted fields |

Parsing is the first step of turning pages into data. The next one, combining and cleaning parsed rows from several sources, is [data wrangling in Python](https://quanticdata.io/blog/data-wrangling-python/). For a complete worked case with numbers, see [scraping Google Finance](https://quanticdata.io/blog/scrape-google-finance/), and for the basics of fetching pages, [web scraping with Python](https://quanticdata.io/blog/how-to-web-scraping-using-python/).

### Sources & further reading

- [Beautiful Soup documentation](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)
- [WHATWG HTML Standard: parsing HTML documents](https://html.spec.whatwg.org/multipage/parsing.html)
- [Python documentation: json, JSON encoder and decoder](https://docs.python.org/3/library/json.html)
- [Unicode: U+00A0 NO-BREAK SPACE (Latin-1 Supplement chart)](https://www.unicode.org/charts/PDF/U0080.pdf)

## FAQ

Quick answers on data parsing.

[Something else? Ask us](mailto:hello@quanticdata.io)

### What is data parsing?

Data parsing is converting raw input, such as HTML, a log line, a CSV file or a PDF, into structured records a program can use. A parser splits the input into pieces, arranges them by the format's rules, then maps the parts you need to named fields with proper types.

### What is an example of data parsing?

Turning the HTML of a web page into records. In our run on 20 November 2026, 34,167 characters of HTML became 30 records with rank, title, link, points, posted time and comments, and strings such as "376 points" became the integer 376.

### What is a data parser?

A data parser is the program or library that does the parsing: the json module for JSON, Beautiful Soup or lxml for HTML, a CSV reader for spreadsheets, or a scraping API that returns extracted fields. Most jobs combine a format parser with custom rules for the fields you need.

### What is the difference between data parsing and data extraction?

Extraction is getting the data out of a source, for example fetching a page and selecting the parts you want. Parsing is interpreting the structure and converting values into fields and types. In practice one script or API call does both, as our server-side example shows.

### What does data parsing error mean?

It means the input did not match what the parser expected: the wrong format (an HTML error page where JSON was expected), the wrong character encoding, a changed page layout, an unexpected value, or a file version the reader does not support.

### How do you parse data in Python?

Use the parser for the format: json for JSON, csv or pandas for tables, Beautiful Soup or lxml for HTML and XML, and re for patterns inside strings. Then convert the strings to numbers and dates and validate that every expected field is present.

## Get pages as HTML, Markdown or parsed fields

Send a URL and selectors, get the fields back typed, at $0.0015 per successful page. Failed requests are free, and every account gets $2 of free API usage a month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-end&utm_content=data-parsing) · [Explore Web Scraping API](https://quanticdata.io/web-scraping-api/)

## Related reading

- [Web Scraping Project Ideas, Started for Real](https://quanticdata.io/blog/web-scraping-project-ideas/): Web scraping · Five web scraping project ideas, each one started for real on 20 November 2026: a price tracker, a library release dashboard, a question analysis, an open-source landscape and a topic timeline, with the code, the first run and what to build next.
- [Retry-After Header: Read It, Wait, Retry](https://quanticdata.io/blog/retry-after-header/): Web scraping · Retry-After tells a client how long to wait before the next request, as a number of seconds or as an HTTP date. Below: both formats, a Python and a Node helper we ran against a real 429 on 20 November 2026 (each waited 10 seconds and then got 200), the rate-limit headers of the QuanticData API, and how one batch job replaced 20 calls.
- [How to Use an API Key: curl, Python and JS](https://quanticdata.io/blog/how-to-use-an-api-key/): Web scraping · An API key is a secret string you send with every request so the service knows which account is calling. Nothing is installed: you add one header. Below: the same call in curl, Python, JavaScript and PowerShell, run on 20 November 2026 against the QuanticData API, the exact 401 messages for the usual mistakes, and how to keep the key out of your code.

---

Source: https://quanticdata.io/blog/data-parsing/ · Site index for AI: https://quanticdata.io/llms.txt
