> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Scrapegraph Tools

> Extract structured data, markdown, and raw HTML from a page using ScrapeGraphTools smartscraper, markdownify, and scrape.

This is an example of how to use the ScrapeGraphTools.

```python scrapegraph_tools.py theme={null}
"""
This is an example of how to use the ScrapeGraphTools.

Prerequisites:
- Create a ScrapeGraphAI account and get an API key at https://scrapegraphai.com
- Set the API key as an environment variable:
    export SGAI_API_KEY=<your-api-key>
"""

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.scrapegraph import ScrapeGraphTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


agent = Agent(
    tools=[
        ScrapeGraphTools(
            enable_smartscraper=True, enable_markdownify=True, enable_scrape=True
        )
    ],
    model=OpenAIResponses(id="gpt-5.4"),
    markdown=True,
)


# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # Should use smartscraper
    agent.print_response(
        "Use smartscraper on https://example.com to extract the page title and main heading. Return them as JSON.",
        stream=True,
    )

    # Should use markdownify
    agent.print_response(
        "Fetch https://example.com and convert it to markdown. Paste the markdown in your reply.",
        stream=True,
    )

    # Should use scrape
    agent.print_response(
        "Use the scrape tool on https://example.com and confirm whether the HTML contains 'Example Domain'.",
        stream=True,
    )
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno openai scrapegraph-py
```

**2. Export your API keys**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
export SGAI_API_KEY="your_sgai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
$Env:SGAI_API_KEY="your_sgai_api_key_here"
```

**3. Run the example**

Save the code above as `scrapegraph_tools.py`, then run:

```bash theme={null}
python scrapegraph_tools.py
```

Full source: [cookbook/91\_tools/scrapegraph\_tools.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/91_tools/scrapegraph_tools.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.