---
title: "Example: Extract Products"
description: "Collect thousands of products and save to CSV"
icon: "database"
---

This example shows how to extract large amounts of product data from an e-commerce site and save it to files.

## Use Case

Extract 1000s of products from multiple categories with:
- Product URLs
- Names and descriptions
- Original and sale prices
- Discount percentages

Save everything to a CSV file for further analysis.

## Code

```python
import asyncio
from openbrowser.code_use import CodeAgent

async def main():
    task = """
    Go to https://www.flipkart.com.
    Collect approximately 50 products from:

    1. Books & Media - 15 products
    2. Sports & Fitness - 15 products
    3. Beauty & Personal Care - 10 products

    Save to products.csv
    """

    agent = CodeAgent(task=task)
    await agent.run()

asyncio.run(main())
```

## How It Works

1. **Agent navigates** to the e-commerce site
2. **Writes JavaScript** to extract product data from each page
3. **Loops through categories** collecting products
4. **Stores in variables** that persist across steps
5. **Saves to CSV** using pandas or csv module
6. **Returns deterministic code** you can modify and rerun

## Key Benefits

- **Function reuse:** Extraction code is written once, used many times
- **Scale:** Easily collect 100s or 1000s of items
- **Deterministic:** The generated Python code can be saved and rerun
- **Data processing:** Built-in pandas support for cleaning and transforming data

[View full example on GitHub →](https://github.com/billy-enrizky/openbrowser-ai/blob/main/examples/code_agent/extract_products.py)
