All articles4 min read
Retail data

Normalize scraped prices without losing their meaning

Preserve currency, units and raw text before comparing prices across pages.

Generated editorial photograph of an ecommerce analyst inspecting comparable retail products beside a laptop.

A price field is more than a number. The amount may describe one item, a multipack, a subscription period or a selected variant. Currency and tax presentation can change between markets. Converting every visible string into a floating-point number before recording that context makes an export easier to sort and harder to trust.

Keep the raw observation

Save the visible price text alongside the normalized amount. Retain the page address, intended market, selected variant and observation time. If parsing fails, keep that failure explicit rather than replacing the amount with zero or silently removing the row.

A currency symbol alone can be ambiguous. Prefer an explicit currency identifier from the page's relevant context when it is available, and record how you obtained it. If different parts of the page disagree, quarantine the observation for review instead of choosing whichever value fits your existing dataset.

Decide which format you are parsing

Decimal and grouping separators differ across formats. Removing every comma and period is not a normalization policy. Determine the expected format for that page or market before converting its values. Unknown formatting should produce a controlled rejection, not a confident guess.

Define how you handle spaces, price ranges and promotional labels. Keep a list price separate from a sale price. A range is not automatically the cheapest purchasable variant, and a missing sale price does not mean that the sale price is zero.

When collecting structured page data, validate it against the visible offer and the intended variant. An amount can be syntactically valid while describing a different seller, product option or availability state. Preserve the distinction between an extraction method and a business interpretation.

Use a deliberate numeric representation

For decimal amounts, constructing a decimal value from a canonical string avoids first introducing a binary floating-point approximation. Converting an already-created binary float to a decimal does not recover the original price text. Decide your storage representation before performing arithmetic.

This Python helper accepts only an illustrative canonical format: ASCII digits, optionally followed by a decimal point and more digits. It does not parse localized text, currency symbols or grouping separators.

import re
from decimal import Decimal

def canonical_price(text):
    if not isinstance(text, str) or len(text) > 128:
        raise ValueError("invalid canonical price")
    if not re.fullmatch(r"[0-9]+(?:\.[0-9]+)?", text):
        raise ValueError("ambiguous or unsupported format")
    return Decimal(text)

A separate, tested normalization step must turn a known localized format into that canonical representation. The length bound is a sample application guard, not a product limit. This helper intentionally rejects negative values; a dataset containing credits or adjustments would need a different contract.

Do not round every currency to two decimal places by habit. Choose precision and rounding rules for the currency and task, and document them. If you use integer minor units instead, keep the currency's applicable scale in the contract rather than assuming one universal multiplier.

Compare equivalent offers

Match the product and variant before comparing amounts. Include pack size and unit of measure when they affect the offer. Treat shipping charges, tax inclusion and membership conditions as separate attributes when your use case needs them. Two identical-looking numbers can describe different purchase conditions.

If you later convert currencies, retain the original amount and currency. Store the conversion rate, its effective time and the rule used for the derived value. Do not rewrite the original observation as though the converted amount appeared on the page.

Test the rejected cases too

Build fixtures for a normal decimal string, a known localized price, an unavailable offer and a range. Include a comma whose meaning is ambiguous, a blank value, a currency mismatch and a different pack size. Confirm that rejection reasons survive into your review output.

Check both parser behavior and dataset coverage during a pilot. A normalization change that accepts more strings can still merge incompatible offers. Sample accepted rows after each change, and keep the record contract version with the batch.

Configure collection through a client integration, then handle price interpretation in the pipeline that owns the dataset. A successful request does not establish that two prices are comparable.

Use the Web Scraping API parsing examples to extract price text. Run your amount and currency checks on the extracted fields before accepting the record.

Contact us

Tell us what you want to collect.

See our Privacy Notice for how we handle your message.

Your message is sent to hello@crawlhub.ai. Please do not include passwords or API keys.