Build a Web Scraping Agent with LlamaIndex

Build a web scraping agent with LlamaIndex and Geekflare to extract webpage content and process website data

Aakash
Updated November 24, 2026
Share

Let’s build a web scraping agent with LlamaIndex and Geekflare. We will use Python to connect the scraping tool, extract content from a website and let the AI agent process the retrieved information.

How to Make a LlamaIndex Agent Scrape Websites

LlamaIndex agents can use external tools to retrieve and process information from websites. You can connect Geekflare’s web scraping tool to a LlamaIndex agent and let it extract webpage content in formats such as Markdown, plain text, HTML, and structured JSON.

Geekflare provides an integration for LlamaIndex with tools for webpage scraping, web search, metadata extraction, screenshots, and other website operations. For this tutorial, we’ll focus on its web scraping capability.

Set Up the Python Environment

Before building the agent, let’s install the required package and configure the API key.

Prerequisites

Make sure you have:

  • Python 3.10 or later.
  • llama-index-core version 0.12 to 0.14.
  • A Geekflare account and API key.
  • An LLM API key. I will use Claude for this tutorial, but you can choose your preferred provider.

Step 1: Install the Python Package

Open your terminal and run:

pip install llama-index-tools-geekflare

This installs Geekflare’s integration package for LlamaIndex.

Step 2: Configure Your Geekflare API Key

Get your API key from the Geekflare dashboard.

Set it as an environment variable so the integration can authenticate your requests.

For macOS or Linux:

export GEEKFLARE_API_KEY="YOUR_GEEKFLARE_API_KEY"

For Windows PowerShell:

$env:GEEKFLARE_API_KEY="YOUR_GEEKFLARE_API_KEY"

Replace the placeholder with your actual API key.

Step 3: Scrape Websites Using LlamaIndex and Geekflare

Geekflare provides two ways to use its web scraping capabilities with LlamaIndex:

  • Direct tool call: Pass a webpage URL and extraction options directly to Geekflare to retrieve its content.
  • AI agent: Connect the scraping tool to a LlamaIndex agent so an LLM can handle scraping requests based on user prompts.

For this example, we’ll use the BBC News website to extract news content and generate a summary.

Method 1: Call the Scraping Tool Directly

You can use GeekflareToolSpec to call the scraping function directly from Python.

Create a file named web_scraping.py and add the following code:

from llama_index.tools.geekflare import GeekflareToolSpec

# Initialize the Geekflare integration
geekflare = GeekflareToolSpec()

# Scrape BBC News and request Markdown output
result = geekflare.scrape(
    "https://www.bbc.com/news",
    formats=["markdown"]
)

# Display the extracted webpage content
print(result)

This code extracts content from BBC News and returns it in Markdown format.

Here is the respone:

LlamaIndex web scraping response

Method 2: Use the Scraping Tool with an AI Agent

The direct method works well when you already know the webpage URL. You can also connect the scraping tool to a LlamaIndex agent and let an LLM decide when to use it based on the user’s request.

For this example, we’ll use Claude Sonnet 5.5.

Create a file named web_scraping_agent.py and add the following code:

import asyncio

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.anthropic import Anthropic
from llama_index.tools.geekflare import GeekflareToolSpec

# Initialize Geekflare
spec = GeekflareToolSpec()

# Select only the webpage scraping tool
tools = [
    tool for tool in spec.to_tool_list()
    if tool.metadata.name == "scrape"
]

# Create a LlamaIndex agent using Claude
agent = FunctionAgent(
    tools=tools,
    llm=Anthropic(model="claude-sonnet-5-5")
)

async def main():
    # Ask the agent to scrape BBC News and summarize its content
    response = await agent.run(
        "Scrape https://www.bbc.com/news "
        "and summarize the main news stories."
    )

    # Display the agent's response
    print(response)

# Run the asynchronous agent workflow
if __name__ == "__main__":
    asyncio.run(main())

The agent uses Geekflare to retrieve BBC News content and Claude to process the extracted information and generate a summary.

Step 4: Run the Web Scraping Agent

Save your code and run the following command in your terminal:

python web_scraping_agent.py

The agent sends the BBC News URL to Geekflare, retrieves the webpage content, and passes the extracted information to Claude for processing.

Claude then generates a summary of the retrieved news content based on your prompt.

Here is the response:

LlamaIndex web scraping agent response

Frequently Asked Questions

Can I use LlamaIndex for web scraping?

Yes. You can connect Geekflare’s scraping tools to LlamaIndex and use them directly or through an AI agent.

Which Python package enables web scraping with LlamaIndex?

The llama-index-tools-geekflare package integrates Geekflare’s web scraping tools with LlamaIndex. It allows developers to extract webpage content directly or through AI agents.

Do I need an LLM to scrape webpages using Geekflare?

No. You can call GeekflareToolSpec().scrape() directly to extract webpage content. An LLM is only required when you want an agent to process or summarize the extracted data.

Conclusion

LlamaIndex makes it easier to build AI agents that can retrieve and process website content. Geekflare adds web scraping capabilities to these agents through its Python integration.

You can call the scraping tool directly to extract webpage content or connect it to a LlamaIndex agent to process and summarize retrieved information using an LLM. Try both methods and choose the one that fits your workflow.

Aakash
Aakash R
Developer Advocate

Aakash R is a Developer Advocate with expertise in Artificial Intelligence, Machine Learning, and Computer Vision. Alongside his work in developer advocacy, he actively contributes technical articles and research-driven content on Generative AI, AI agents, developer tools, and cloud platforms. He enjoys translating advanced AI concepts into practical resources that developers can apply in real projects.

Thanks to Our Partners

More from Geekflare

Dev Hub
10 Best Android Emulators for PC and Mac

An Android emulator runs the Android operating system inside a window on your Windows PC or…

How to Give a LangChain Agent Screenshot Capabilities
Dev Hub
How to Give a LangChain Agent Screenshot Capabilities

Give a LangChain agent screenshot capabilities to capture webpages and retrieve visual content.

Dev Hub
12 Best MCP Servers for Financial Data in 2026

Official MCP servers for financial data compared, with results from testing in Claude Code.