ZenRows® provides multiple ways to extract and format data from web pages. You can use CSS Selectors for direct JSON extraction, apply output filters for data transformation, or retrieve raw HTML for custom processing. This guide covers three main approaches to data extraction with ZenRows.
CSS Selectors are a query language for selecting HTML elements. When you enable the css_extractor parameter, ZenRows returns structured JSON data instead of raw HTML.Let’s say you want to scrape the title from the ScrapingCourse eCommerce page. The title is contained in an h1 tag.To extract it, send the css_extractor parameter with the value {"title": "h1"}. Make sure the parameter is properly encoded
import requests

api_key = "YOUR_ZENROWS_API_KEY"
url = "https://www.scrapingcourse.com/ecommerce/"
css_extractor = {"title": "h1"}

response = requests.get(
    "https://api.zenrows.com/v1/",
    params={
        "apikey": api_key,
        "url": url,
        "css_extractor": css_extractor
    }
)

print(response.json())
This code sends a request to ZenRows with the CSS selector h1 mapped to the key “title”. ZenRows extracts the content from the first h1 element and returns it as structured JSON data.

Extracting Multiple Elements

Now let’s extract multiple elements. Add the product names using the selector .product-name:
import requests

api_key = "YOUR_ZENROWS_API_KEY"
url = "https://www.scrapingcourse.com/ecommerce/"
css_extractor = {
    "title": "h1",
    "products": ".product-name"
}

response = requests.get(
    "https://api.zenrows.com/v1/",
    params={
        "apikey": api_key,
        "url": url,
        "css_extractor": css_extractor
    }
)

print(response.json())
This request extracts both the page title and all product names. When a CSS selector matches multiple elements, ZenRows automatically returns them as an array.The response looks like this:
{
    "title": "E-commerce Products",
    "products": [
        "Product 1",
        "Product 2",
        "Product 3"
        // ...
    ]
}

Extracting attributes

You might need product links to continue scraping individual product details. To extract the href attribute instead of text content, add @href to your selector.Let’s filter links to only include those starting with /product/:
import requests

api_key = "YOUR_ZENROWS_API_KEY"
url = "https://www.scrapingcourse.com/ecommerce/"
css_extractor = {
    "title": "h1",
    "products": ".product-name",
    "links": "a[href*='/product/'] @href"
}

response = requests.get(
    "https://api.zenrows.com/v1/",
    params={
        "apikey": api_key,
        "url": url,
        "css_extractor": css_extractor
    }
)

print(response.json())
The @href syntax tells ZenRows to extract the href attribute value instead of the element’s text content. The [href*='/product/'] part filters links to only include those containing /product/ in their href attribute.This returns:
{
    "title": "Shop",
    "products": [
        "Product 1",
        "Product 2",
        "Product 3"
        // ...
    ],
    "links": [
        "/product/1",
        "/product/2",
        "/product/3"
        // ...
    ]
}

Testing Your Selectors

Before implementing your scraper at scale, test your CSS selectors using our Builder. The Builder shows you the extracted data in real-time and generates code in multiple programming languages for easy integration.
Extract Data using CSS Selectors

When to use each method

Choose your data extraction method based on your specific needs:
  • CSS Selectors - Best for custom data extraction when you know exactly what elements you need. Returns clean JSON data with your own key names and structure.
  • Output Filters - Ideal for extracting common data types like emails, phone numbers, images, and links. Perfect when you need standard web data without custom parsing.
  • External Libraries - Perfect when you need complex parsing logic, custom data transformations, or when integrating with existing parsing workflows.

Further Reading

For more advanced CSS selector patterns and examples for complex web layouts, check out our Advanced CSS Selector Examples guide.