Zenrows
Talk to sales Start building free

Web Scraping With LangChain and ZenRows

Learn how to integrate web scraping into your LangChain workflows. Discover step-by-step guides and real-world examples for enhancing your AI agents with up-to-date web data.

Imagine a LangChain/LangGraph workflow with access to fresh, accurate, real-time web data, all enabled by web scraping. Unfortunately, standard web scraping tools often fail against modern anti-bot defenses, leaving your AI agents in the dark.

In this article, we'll show you how to create a reliable LangChain scraping integration that consistently fetches real-time data without interruptions. You'll learn about the core challenges, why your Langchain workflow needs a dedicated scraping solution, and the simple integration that guarantees success.

Why LangChain Agents Need Access to Web Data?

LangChain enables you to build AI agents, from individual task automation to full-blown, interconnected workflows. While it supports RAG (Retrieval Augmented Generation) orchestration, LangChain's access to live web data is limited.

Integrating web scraping with LangChain solves the web access limitation problem by exposing your workflow to real-time web data that isn't available through traditional sources. Scraped data enhances your AI agents with richer context, higher accuracy, and up-to-date information for better decision-making.

Companies are rapidly building AI-assisted systems using web-scraped data to accelerate development and deliver value more quickly.

Some use cases for LangChain's web scraping integration include competitor analysis, market research, news aggregation, sentiment analysis, pricing intelligence, compliance tracking, lead generation, real-time trend monitoring, and more.

Despite these benefits, web scraping also has its downsides. Most scraping tools are prone to anti-bot detection, resulting in imminent bans and denying your system access to live data.

Skip the blocks. Try Zenrows free and get clean web data without the anti-bot fight.

Challenges of Traditional Web Scraping

Anti-bot walls resulting in 403 Forbidden Errors, JavaScript rendering leading to empty content, rate-limited IP bans, and more are all against web scrapers. If you allow this to continue, your AI agent will hallucinate, and your decision model will lose its sole source of up-to-date intelligence.

Here's a sample block message returned by a LangChain AI agent, indicating it can't access the target site due to an anti-bot measure:

{
    #...,
    "output": "I am unable to access the content of the page at the provided URL due to an anti-bot challenge. The page requires JavaScript and cookies to be enabled in order to view its content. Therefore, I cannot provide the major highlight of that page. If you have specific questions or need information about a particular topic, feel free to ask!",
}

While integrating web scraping capabilities into LangChain, it's essential to build a reliable system that can bypass anti-bot detection at scale. This prevents your workflow from breaking.

Next, we show you how to avoid getting blocked while using web scraping in LangChain.

Integrate ZenRows with LangChain/LangGraph

Integrating ZenRows with LangChain removes the limitations of being blocked, ensuring your agents have consistent, real-time access to web data.

ZenRows handles all the technicalities of scraping behind the scenes, including bypassing anti-bot measures, accessing dynamic content, extracting localized data across various regions, and more. This auto-scaled, auto-managed infrastructure lets your team focus on fine-tuning your workflows rather than wasting time building, managing, and debugging in-house scraping systems.

For example, a leading workflow automation company, Clay, uses ZenRows to transform data enrichment in its operations. ZenRows supports LangChain integration out of the box using the langchain-zenrows module.

Next, we'll see a use case in which the langchain-zenrows module scrapes data from the Antibot Challenge page and passes it to a LangChain AI agent for analysis.

Prerequisites

You'll need the following tools to integrate ZenRows with LangChain:

  • Python: Download and install the latest Python version if you've not already done so.
  • Access to an LLM's API: We'll use OpenAI in this tutorial. So, grab your OpenAI API key. But feel free to use any LLM tool that works best for you.
  • Langchain-ZenRows module: To seamlessly integrate the ZenRows Universal Scraper API with your LangChain workflow.

To begin, install langchain-zenrows, langrgraph, and langchain-openai packages using pip:

pip3 install langchain-zenrows langgraph langchain-openai

Scrape Protected Pages with ZenRows in LangChain

First, sign up with ZenRows for free to get your API key.

Import ZenRowsUniversalScraper from langchain_zenrows. Set your ZenRows and OpenAI API keys and instantiate ZenRows as the scraping tool. Here's the complete code:

# pip3 install langchain langchain-openai langchain-zenrows
from langchain_zenrows import ZenRowsUniversalScraper
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
import os

# set your ZenRows API key
os.environ["ZENROWS_API_KEY"] = "<YOUR_ZENROWS_API_KEY>"

# set your OpenAI API key
os.environ["OPENAI_API_KEY"] = "<YOUR_OPENAI_API_KEY>"

def scraper(url: str) -> str:
    # initialize the model
    llm = ChatOpenAI(model="gpt-4o-mini")

    # initialize the universal scraper
    zenrows_tool = ZenRowsUniversalScraper()

    # create an agent that uses ZenRows as a tool
    agent = create_react_agent(llm, [zenrows_tool])

    try:
        # create a prompt
        result = agent.invoke({"messages": f"What is the major highlight on {url}."})

        # extract the response
        for message in result["messages"]:
            print(f"{message.content}")

    except NameError:
        print("Agent not available.")
    except Exception as e:
        print(f"Error running agent: {e}")

scraper("https://www.scrapingcourse.com/antibot-challenge/")

The ZenRows scraper tool bypasses the anti-bot challenge and grants the AI agent access to the website's data. Here's a success sample response from the agent:

The major highlight on the [Antibot Challenge](https://www.scrapingcourse.com/antibot-challenge/) page from ScrapingCourse.com is the notification that users have successfully bypassed the Antibot challenge. The challenge is visually represented with the message:

"You bypassed the Antibot challenge! :D"

This indicates that the page is designed to test and demonstrate the ability to navigate through anti-bot measures effectively.

Congratulations! 🎉 You just built an anti-bot-resistant LangGraph system using Langchain-Zenrows integration. You're ready to build at scale without getting blocked.

Real-World Example: News Summarizer AI Agent with LangGraph-ZenRows Integration

In this example, you'll build a news summarizer agent that analyzes TechCrunch content and returns the top technology stories.

We'll use the following prompt for this use case demonstration:

Go to TechCrunch.com, scrape the homepage in markdown format, and provide a summary of the top 2 technology stories with their headlines and brief descriptions

To build the summarizer, update your code as shown below:

# pip3 install langchain langchain-openai langchain-zenrows
from langchain_zenrows import ZenRowsUniversalScraper
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
import os

# set your ZenRows API key
os.environ["ZENROWS_API_KEY"] = "<YOUR_ZENROWS_API_KEY>"

# set your OpenAI API key
os.environ["OPENAI_API_KEY"] = "<YOUR_OPENAI_API_KEY>"

def scraper() -> str:
    # initialize the model
    llm = ChatOpenAI(model="gpt-4o-mini")

    # initialize the universal scraper
    zenrows_tool = ZenRowsUniversalScraper()

    # create an agent that uses ZenRows as a tool
    agent = create_react_agent(llm, [zenrows_tool])

    try:
        # create a prompt
        result = agent.invoke(
            {
                "messages": "Go to TechCrunch.com, scrape the homepage in markdown format, and provide a summary of the top 2 technology stories with their headlines and brief descriptions"
            }
        )

        # extract the response
        for message in result["messages"]:
            print(f"{message.content}")

    except NameError:
        print("Agent not available.")
    except Exception as e:
        print(f"Error running agent: {e}")

scraper()

And here's the sample output:

Here is the summary of the top two technology stories from the TechCrunch homepage:

### 1. [With an Intel recovery underway, all eyes turn to its foundry business](https://techcrunch.com/2025/10/23/with-an-intel-recovery-underway-all-eyes-turn-to-its-foundry-business/)
*By Rebecca Szkutak, 12 hours ago*
Intel is undergoing a recovery, and attention is now focused on its foundry business as a potential catalyst for significant growth. This shift in strategy could position Intel as a strong player in the semiconductor manufacturing sector.

### 2. [OpenAI buys Sky, an AI interface for Mac](https://techcrunch.com/2025/10/23/openai-buys-sky-an-ai-interface-for-mac/)
*By Sarah Perez, 15 hours ago*
OpenAI has acquired Sky, an AI interface designed for Mac users. This acquisition is part of OpenAI's broader strategy to integrate advanced AI capabilities across various user platforms, enhancing user experience and functionality.

These stories highlight significant developments in the tech industry, emphasizing shifts in major companies' strategies to adapt to the evolving market landscape.

Bravo! You just built a news summarizer tool using LangChain-ZenRows integration. Again, you've provided your LangChain AI agent with real-time news data to make decisions on.

Conclusion

You've seen how to build a LangChain web scraper, including creating a scraper tool that supplies real-time data to an AI agent. You've also learned how to optimize your workflow with a scraping solution to avoid getting blocked.

Remember that building an efficient system with LangChain requires consistent access to data. To scrape without getting blocked, we recommend using ZenRows, a reliable, LangChain-friendly solution that scales with your needs.

Try ZenRows for free now or speak with sales!

FAQ

Can I use other LLMs with LangChain Scraper?

Yes! LangChain is LLM-agnostic, and you're free to use your chosen LLM, as long as you have API access. Simply change the LLM instantiation line, and the agent's logic remains functional.

Can I build a RAG system with LangChain?

Absolutely! And this is one of the use cases of integrating web scraping with LangChain. While a standard RAG system uses a static knowledge base like PDFs, you can use a LangChain Scraper Agent to perform real-time information retrieval. Instead of retrieving a static document, the agent uses the scraping tool to get the most current web data, which it then uses as a basis for its response, ensuring the information is always fresh.

Can LangChain handle dynamic content?

While LangChain itself isn't a scraping or headless browser tool, its ability to integrate with a scraping solution like ZenRows allows it to handle dynamic content effectively. By connecting LangChain to ZenRows, you can extract dynamic data and then process or analyze it within your LangChain workflows.