Skip to main content

Library for extracting structured data from websites using ScrapeGraphAI

Project description

🕷️🦜 langchain-scrapegraph

License Python Support Documentation

Supercharge your LangChain agents with AI-powered web scraping capabilities. LangChain-ScrapeGraph provides a seamless integration between LangChain and ScrapeGraph AI, enabling your agents to extract structured data from websites using natural language.

📦 Installation

pip install langchain-scrapegraph

🛠️ Available Tools

📝 MarkdownifyTool

Convert any webpage into clean, formatted markdown.

from langchain_scrapegraph.tools import MarkdownifyTool

tool = MarkdownifyTool()
markdown = tool.invoke({"website_url": "https://example.com"})

print(markdown)

🔍 SmartscraperTool

Extract structured data from any webpage using natural language prompts.

from langchain_scrapegraph.tools import SmartscraperTool

# Initialize the tool (uses SGAI_API_KEY from environment)
tool = SmartscraperTool()

# Extract information using natural language
result = tool.invoke({
    "website_url": "https://www.example.com",
    "user_prompt": "Extract the main heading and first paragraph"
})

print(result)

💻 LocalscraperTool

Extract information from HTML content using AI.

from langchain_scrapegraph.tools import LocalscraperTool

tool = LocalscraperTool()
result = tool.invoke({
    "user_prompt": "Extract all contact information",
    "website_html": "<html>...</html>"
})

print(result)

🌟 Key Features

  • 🐦 LangChain Integration: Seamlessly works with LangChain agents and chains
  • 🔍 AI-Powered Extraction: Use natural language to describe what data to extract
  • 📊 Structured Output: Get clean, structured data ready for your agents
  • 🔄 Flexible Tools: Choose from multiple specialized scraping tools
  • Async Support: Built-in support for async operations

💡 Use Cases

  • 📖 Research Agents: Create agents that gather and analyze web data
  • 📊 Data Collection: Automate structured data extraction from websites
  • 📝 Content Processing: Convert web content into markdown for further processing
  • 🔍 Information Extraction: Extract specific data points using natural language

🤖 Example Agent

from langchain.agents import initialize_agent, AgentType
from langchain_scrapegraph.tools import SmartscraperTool
from langchain_openai import ChatOpenAI

# Initialize tools
tools = [
    SmartscraperTool(),
]

# Create an agent
agent = initialize_agent(
    tools=tools,
    llm=ChatOpenAI(temperature=0),
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True
)

# Use the agent
response = agent.run("""
    Visit example.com, make a summary of the content and extract the main heading and first paragraph
""")

⚙️ Configuration

Set your ScrapeGraph API key in your environment:

export SGAI_API_KEY="your-api-key-here"

Or set it programmatically:

import os
os.environ["SGAI_API_KEY"] = "your-api-key-here"

📚 Documentation

💬 Support & Feedback

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

This project is built on top of:


Made with ❤️ by ScrapeGraph AI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_scrapegraph-1.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_scrapegraph-1.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file langchain_scrapegraph-1.1.0.tar.gz.

File metadata

  • Download URL: langchain_scrapegraph-1.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for langchain_scrapegraph-1.1.0.tar.gz
Algorithm Hash digest
SHA256 613b263a813d20dcf462395597ff6e5656b047aa85f82ed4a99e4f92037dbd04
MD5 3b3b067a2223c70b6f76d7b2bf8f9670
BLAKE2b-256 f709ccb1c5aa7709f72511b2a23ac4dd185c2cf6d581ed595b61634a8276420a

See more details on using hashes here.

File details

Details for the file langchain_scrapegraph-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_scrapegraph-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9228a5dcfc510fffb98f59e5c30bcee5e200067a6ee69df8cf810e9a48d35737
MD5 9ea346d3c543090ece7101446fe7efa4
BLAKE2b-256 e453af17d45247eef9993befcd10591ab0a0eada29d16aaea3398feb963370ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page