# H\&M (`datasaurus/hm-products`) Actor

Scrape products from H\&M websites. All countries and languages. Fast and efficient.

- **URL**: https://apify.com/datasaurus/hm-products.md
- **Developed by:** [datasaurus](https://apify.com/datasaurus) (community)
- **Categories:** E-commerce
- **Stats:** 33 total users, 2 monthly users, 100.0% runs succeeded, 3 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## H&M Products Scraper

This tool scrapes product data from H&M. It works with all website countries and languages.

Checkout our other scrapers: [Zara](https://apify.com/datasaurus/zara) | [Stradivarius](https://apify.com/datasaurus/stradivarius) | [Pull&Bear](https://apify.com/datasaurus/pullandbear) | [MassimoDutti](https://apify.com/datasaurus/massimodutti) | [Bershka](https://apify.com/datasaurus/bershka) | [Oysho](https://apify.com/datasaurus/oysho) | [ZaraHome](https://apify.com/datasaurus/zarahome)

### Features

- **Detailed Scrape**:
    - Scrapes individual product pages for detailed information
    - <span style="color:">**Fields include**: name, description, price, colors, sizes, SKUs, category, images, stock availability, discount, product page url, plus more. </span>
    - <span style="color:MediumSeaGreen">**Approx Run time**: 1000 products in 30 seconds</span>

- **Granularity**: Scrape:
    - The entire website, e.g. [https://www2.hm.com/en_gb/](https://www2.hm.com/en_gb/)
    - Product category pages, e.g. [https://www2.hm.com/en_gb/home/seasonal-trending/bestsellers.html](https://www2.hm.com/en_gb/home/seasonal-trending/bestsellers.html)

- **Multiple URLs**: Scrape data from multiple start urls within a single scrape, including from different country websites.

- **Set Limits**: Define the maximum products pages to scrape per url.

- **Deduplication**: Unique products are returned, even across multiple start URLs. This is useful in instances where the same product appears in multiple subcategories. The scrapper will do it's best to deduplicate results - as pages are scrapped concurrently, the scrapper may occassionally not identify every duplicate product.


### Notes

- This tool is configured to use datacentre proxies which are low cost and necessay to avoid IP address blocking. It is effecient with data download sizes which optimises run time and cost.
- The output is in JSON format due to the nested data structure.

### Known Scraping Challenges
- Occasionally the scrape might not start or the scrape might stop due to requests being blocked by the website. A '403 error' will appear in the logs. This is common in webscrapping and difficult to avoid, but it can be solved by re-running the scrape.

### Resources

- **Getting Started with Apify**:
    - [Getting Started with Apify 1/4 - Introduction](https://www.youtube.com/watch?v=b_nep8vMnkc&list=PLObrtcm1Kw6MUrlLNDbK9QRg8VDJg0gOW&index=1)
    - [Getting Started with Apify 4/4 - Integrations](https://www.youtube.com/watch?v=bNACk1_S_6w&list=PLObrtcm1Kw6MUrlLNDbK9QRg8VDJg0gOW&index=4)
    - [Try Apify for Free - 2,000+ Pre-built Web Scraping and Automation Tools](https://www.youtube.com/watch?v=WQNgQVRG9_U)
    - [Integration with Make, GitHub, Zapier, Google Drive, and other apps](https://apify.com/integrations)
    - [How to Train ChatGPT on Your Own Data - Build a Custom AI Chatbot](https://www.youtube.com/watch?v=LcG919C4UeU)
    - [Apify Platform Documentation](https://docs.apify.com/platform)


### Example Input
```json
{
  "start_urls": [
    {"url": "https://www2.hm.com/en_gb/index.html"},
    {"url": "https://www2.hm.com/en_gb/home/seasonal-trending/bestsellers.html"},
  ],
  "deduplicate_across_all_start_urls": true,
  "max_categories": 1,
  "max_pages": 1
}
````

### Example Output

```json
{
  "id": "0974175002",
  "trackingId": "OzU7IzswOTc0MTc1MDAyOyM7IzsvZmFzaGlvbi9NT0JJTEUvTEFORElOR19QQUdFL05BVklHQVRJT05fUkVTVUxUOyM7IztPQkpFQ1RJVkUkOzExOzQ3OyM7IzsvaG9tZTs_e4",
  "productName": "Cotton storage basket",
  "external": false,
  "brandName": "H&M",
  "url": "https://www2.hm.com/en_gb/productpage.0974175002.html",
  "showPriceMarker": false,
  "prices": [
    {
      "priceType": "whitePrice",
      "price": 19.99,
      "minPrice": 19.99,
      "maxPrice": 19.99,
      "formattedPrice": "£19.99"
    }
  ],
  "availability": {
    "stockState": "Available",
    "comingSoon": false
  },
  "swatches": [
    {
      "articleId": "0974175002",
      "url": "https://www2.hm.com/en_gb/productpage.0974175002.html",
      "colorName": "Light beige",
      "colorCode": "B5AFA0",
      "trackingId": "OzU7IzswOTc0MTc1MDAyOyM7IzsvZmFzaGlvbi9NT0JJTEUvTEFORElOR19QQUdFL05BVklHQVRJT05fUkVTVUxUOyM7IztPQkpFQ1RJVkUkOzExOzQ3OyM7IzsvaG9tZTs_e4",
      "productImage": "https://image.hm.com/assets/hm/9d/b2/9db248e3025308a910b4d3cd543ec33803f09cd2.jpg"
    }
  ],
  "productMarkers": [],
  "images": [
    {
      "url": "https://image.hm.com/assets/hm/d2/c3/d2c3427b67121103bce070735bebc6a76b6f824d.jpg"
    },
    {
      "url": "https://image.hm.com/assets/hm/cd/b3/cdb3cc592089d526a1563e8d4f4ca3c0ea53346d.jpg"
    }
  ],
  "hasVideo": false,
  "removed": false,
  "colorName": "Light beige",
  "isPreShopping": false,
  "isOnline": true,
  "modelImage": "https://image.hm.com/assets/hm/ec/7c/ec7c5c8be146f7c79343fa550b3eb8e082b0259e.jpg",
  "colors": "B5AFA0",
  "productImage": "https://image.hm.com/assets/hm/9d/b2/9db248e3025308a910b4d3cd543ec33803f09cd2.jpg",
  "sizes": [
    {
      "id": "001",
      "label": "NOSIZE",
      "stock": 2
    }
  ],
  "newArrival": false,
  "isLiquidPixelUrl": false,
  "colorWithNames": "beige_f5f5dc",
  "mainCatCode": "home_storageorganizing_baskets"
}
```

# Actor input Schema

## `start_urls` (type: `array`):

Website: e.g.
https://www2.hm.com/en\_gb/index.html
-see Information tab for a list of country websites-
Category page: e.g.
https://www2.hm.com/en\_gb/home/seasonal-trending/bestsellers.html

## `max_categories` (type: `integer`):

Select the number of category product pages to scrape per url. This works with main page urls only.

## `max_pages` (type: `integer`):

Select the maximum number of pages to scrape per start url.

## Actor input object example

```json
{
  "start_urls": [
    {
      "url": "https://www2.hm.com/en_gb/index.html"
    },
    {
      "url": "https://www2.hm.com/en_gb/home/seasonal-trending/bestsellers.html"
    }
  ],
  "max_categories": 2,
  "max_pages": 1
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "start_urls": [
        {
            "url": "https://www2.hm.com/en_gb/index.html"
        },
        {
            "url": "https://www2.hm.com/en_gb/home/seasonal-trending/bestsellers.html"
        }
    ],
    "max_pages": 1
};

// Run the Actor and wait for it to finish
const run = await client.actor("datasaurus/hm-products").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "start_urls": [
        { "url": "https://www2.hm.com/en_gb/index.html" },
        { "url": "https://www2.hm.com/en_gb/home/seasonal-trending/bestsellers.html" },
    ],
    "max_pages": 1,
}

# Run the Actor and wait for it to finish
run = client.actor("datasaurus/hm-products").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "start_urls": [
    {
      "url": "https://www2.hm.com/en_gb/index.html"
    },
    {
      "url": "https://www2.hm.com/en_gb/home/seasonal-trending/bestsellers.html"
    }
  ],
  "max_pages": 1
}' |
apify call datasaurus/hm-products --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=datasaurus/hm-products",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "H&M",
        "description": "Scrape products from H&M websites. All countries and languages. Fast and efficient.",
        "version": "0.1",
        "x-build-id": "wKFkuIXKAW1nTl4uL"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/datasaurus~hm-products/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-datasaurus-hm-products",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/datasaurus~hm-products/runs": {
            "post": {
                "operationId": "runs-sync-datasaurus-hm-products",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/datasaurus~hm-products/run-sync": {
            "post": {
                "operationId": "run-sync-datasaurus-hm-products",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "start_urls"
                ],
                "properties": {
                    "start_urls": {
                        "title": "Start URLs - full website, category page or product page",
                        "uniqueItems": true,
                        "type": "array",
                        "description": "Website: e.g.\nhttps://www2.hm.com/en_gb/index.html\n-see Information tab for a list of country websites-\nCategory page: e.g.\nhttps://www2.hm.com/en_gb/home/seasonal-trending/bestsellers.html",
                        "default": [
                            {
                                "url": "https://www2.hm.com/en_gb/index.html"
                            }
                        ],
                        "items": {
                            "type": "object",
                            "required": [
                                "url"
                            ],
                            "properties": {
                                "url": {
                                    "type": "string",
                                    "title": "URL of a web page",
                                    "format": "uri"
                                }
                            }
                        }
                    },
                    "max_categories": {
                        "title": "Max Categories per start url - use when scraping whole site",
                        "minimum": 1,
                        "maximum": 100000,
                        "type": "integer",
                        "description": "Select the number of category product pages to scrape per url. This works with main page urls only.",
                        "default": 2
                    },
                    "max_pages": {
                        "title": "Max Pages per start url (72 items per page).",
                        "minimum": 1,
                        "maximum": 100000,
                        "type": "integer",
                        "description": "Select the maximum number of pages to scrape per start url.",
                        "default": 1
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
