How to Scrape H&M Data: Complete Guide for 2026
Tutorials

How to Scrape H&M Data: Complete Guide for 2026

Learn to scrape H&M product data with Python and Node.js using AlterLab’s API. Covers anti-bot handling, structured extraction, pricing, and responsible scraping practices.

4 min read
6 views

AlterLab handles this automaticallyscrape any URL with one API call. No infrastructure required.

Try it free

This guide covers extracting publicly accessible data. Always review a site's robots.txt and Terms of Service before scraping.

TL;DR

To scrape H&M product pages, send a request to AlterLab’s API with the target URL, parse the returned HTML with CSS selectors, and optionally use Cortex for typed JSON output. Start at tier T1 and let the API promote automatically if anti‑bot measures require more advanced handling.

Why collect e-commerce data from H&M?

  • Price monitoring: Track changes in product pricing across categories to inform competitive pricing strategies.
  • Market research: Analyze product availability, description updates, and new arrivals to spot trends.
  • Data analysis: Build datasets for machine learning models that predict fashion demand or style popularity.

Technical challenges

H&M’s public pages include typical e‑commerce protections: rate limiting per IP, header validation (User‑Agent, Accept), and occasional JavaScript‑based checks that block simple HTTP clients. Raw requests often receive HTTP 429 or challenge pages. AlterLab’s Smart Rendering API manages proxy rotation, header generation, and headless browser fallback, letting you focus on data extraction rather than bypass mechanics.

Quick start with AlterLab API

First, install the SDK and make a basic scrape request. The examples below show Python, Node.js, and cURL. For setup details, see the Getting started guide.

Python
import alterlab

client = alterlab.Client("YOUR_API_KEY")
response = client.scrape("https://www2.hm.com/en_us/productpage.1234567890.html")
print(response.text[:500])
JAVASCRIPT
import { AlterLab } from "alterlab";

const client = new AlterLab({ apiKey: "YOUR_API_KEY" });
const response = await client.scrape("https://www2.hm.com/en_us/productpage.1234567890.html");
console.log(response.text.slice(0, 500));
Bash
curl -X POST https://api.alterlab.io/v1/scrape \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"url": "https://www2.hm.com/en_us/productpage.1234567890.html"}'

The response contains the raw HTML of the product page. You can now parse it with libraries like BeautifulSoup (Python) or cheerio (Node.js).

Extracting structured data

Once you have the HTML, target visible elements with CSS selectors. On an H&M product page, common data points include:

  • Product title: h1.product-item-headline
  • Price: span.price-value
  • Rating: div.rating-stars (data‑rating attribute)
  • Description: div.pdp-description-inner

Python example with BeautifulSoup

Python
from bs4 import BeautifulSoup
import alterlab

client = alterlab.Client("YOUR_API_KEY")
html = client.scrape("https://www2.hm.com/en_us/productpage.1234567890.html").text
soup = BeautifulSoup(html, "html.parser")

title = soup.select_one("h1.product-item-headline").get_text(strip=True)
price = soup.select_one("span.price-value").get_text(strip=True)
rating_elem = soup.select_one("div.rating-stars")
rating = rating_elem["data-rating"] if rating_elem else None
description = soup.select_one("div.pdp-description-inner").get_text(strip=True)

print({"title": title, "price": price, "rating": rating, "description": description})

Node.js example with cheerio

JAVASCRIPT
import { AlterLab } from "alterlab";
import cheerio from "cheerio";

const client = new AlterLab({ apiKey: "YOUR_API_KEY" });
const html = await client.scrape("https://www2.hm.com/en_us/productpage.1234567890.html");
const $ = cheerio.load(html);

const title = $("h1.product-item-headline").text().trim();
const price = $("span.price-value").text().trim();
const rating = $("div.rating-stars").attr("data-rating");
const description = $(".pdp-description-inner").text().trim();

console.log({ title, price, rating, description });

Structured JSON extraction with Cortex

For a more direct approach, use AlterLab’s Cortex extraction API to receive typed JSON without writing selectors. Define a JSON Schema that matches the fields you need.

Python
import alterlab

client = alterlab.Client("YOUR_API_KEY")
result = client.extract(
    url="https://www2.hm.com/en_us/productpage.1234567890.html",
    schema={
        "type": "object",
        "properties": {
            "title": {"type": "string"},
            "price": {"type": "number"},
            "rating": {"type": "number"},
            "description": {"type": "string"}
        },
        "required": ["title", "price"]
    }
)
print(result.data)  # Typed JSON output

Cortex returns validated JSON, reducing post‑processing work and handling page variations automatically.

Cost breakdown

AlterLab’s pricing is usage‑based. The table below shows the cost per request and per 1,000 requests for each tier. For H&M, start at T1; the API will promote to T2‑T4 if anti‑bot measures require more advanced handling, and you only pay for the tier that succeeds.

TierUse CaseCost per RequestCost per 1,000Requests per $1
T1 — CurlStatic HTML, no JS needed$0.0002$0.205,000
T2 — HTTPStandard pages with headers$0.0003$0.303,333
T3 — StealthProtected pages, anti-bot active$0.002$2.00500
T4 — BrowserFull JS rendering required$0.004$4.00250
T5 — CAPTCHACAPTCHA solving + JS rendering$0.02$20.0050

See the full AlterLab pricing page for volume discounts and enterprise options.

99.2%Success Rate
1.2sAvg Response
Share

Was this article helpful?

Frequently Asked Questions

Scraping publicly accessible data is generally permissible under rulings like hiQ v LinkedIn, but you must review H&M’s robots.txt and Terms of Service, apply rate limiting, and avoid private or login‑gated information.
H&M employs standard anti‑bot measures such as request rate limits, header checks, and occasional JavaScript challenges. AlterLab’s Smart Rendering API automatically handles proxy rotation, header generation, and browser rendering when needed.
Costs start at $0.0002 per request for static HTML (T1) and rise to $0.004 per request for full JavaScript rendering (T4). AlterLab auto‑escalates tiers, so you only pay for the level that succeeds.