|
1 |
| -# langchain-scrapegraph |
| 1 | +# 🕷️🦜 langchain-scrapegraph |
| 2 | + |
| 3 | +[](https://opensource.org/licenses/MIT) |
| 4 | +[](https://pypi.org/project/langchain-scrapegraph/) |
| 5 | +[](https://scrapegraphai.com/docs) |
| 6 | + |
| 7 | +Supercharge your LangChain agents with AI-powered web scraping capabilities. LangChain-ScrapeGraph provides a seamless integration between [LangChain](https://github.com/langchain-ai/langchain) and [ScrapeGraph AI](https://scrapegraphai.com), enabling your agents to extract structured data from websites using natural language. |
| 8 | + |
| 9 | +## 📦 Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +pip install langchain-scrapegraph |
| 13 | +``` |
| 14 | + |
| 15 | +## 🛠️ Available Tools |
| 16 | + |
| 17 | +### 📝 MarkdownifyTool |
| 18 | +Convert any webpage into clean, formatted markdown. |
| 19 | + |
| 20 | +```python |
| 21 | +from langchain_scrapegraph.tools import MarkdownifyTool |
| 22 | + |
| 23 | +tool = MarkdownifyTool() |
| 24 | +markdown = tool.invoke({"website_url": "https://example.com"}) |
| 25 | + |
| 26 | +print(markdown) |
| 27 | +``` |
| 28 | + |
| 29 | +### 🔍 SmartscraperTool |
| 30 | +Extract structured data from any webpage using natural language prompts. |
| 31 | + |
| 32 | +```python |
| 33 | +from langchain_scrapegraph.tools import SmartscraperTool |
| 34 | + |
| 35 | +# Initialize the tool (uses SGAI_API_KEY from environment) |
| 36 | +tool = SmartscraperTool() |
| 37 | + |
| 38 | +# Extract information using natural language |
| 39 | +result = tool.invoke({ |
| 40 | + "website_url": "https://www.example.com", |
| 41 | + "user_prompt": "Extract the main heading and first paragraph" |
| 42 | +}) |
| 43 | + |
| 44 | +print(result) |
| 45 | +``` |
| 46 | + |
| 47 | +### 💻 LocalscraperTool |
| 48 | +Extract information from HTML content using AI. |
| 49 | + |
| 50 | +```python |
| 51 | +from langchain_scrapegraph.tools import LocalscraperTool |
| 52 | + |
| 53 | +tool = LocalscraperTool() |
| 54 | +result = tool.invoke({ |
| 55 | + "user_prompt": "Extract all contact information", |
| 56 | + "website_html": "<html>...</html>" |
| 57 | +}) |
| 58 | + |
| 59 | +print(result) |
| 60 | +``` |
| 61 | + |
| 62 | +## 🌟 Key Features |
| 63 | + |
| 64 | +- 🐦 **LangChain Integration**: Seamlessly works with LangChain agents and chains |
| 65 | +- 🔍 **AI-Powered Extraction**: Use natural language to describe what data to extract |
| 66 | +- 📊 **Structured Output**: Get clean, structured data ready for your agents |
| 67 | +- 🔄 **Flexible Tools**: Choose from multiple specialized scraping tools |
| 68 | +- ⚡ **Async Support**: Built-in support for async operations |
| 69 | + |
| 70 | +## 💡 Use Cases |
| 71 | + |
| 72 | +- 📖 **Research Agents**: Create agents that gather and analyze web data |
| 73 | +- 📊 **Data Collection**: Automate structured data extraction from websites |
| 74 | +- 📝 **Content Processing**: Convert web content into markdown for further processing |
| 75 | +- 🔍 **Information Extraction**: Extract specific data points using natural language |
| 76 | + |
| 77 | +## 🤖 Example Agent |
| 78 | + |
| 79 | +```python |
| 80 | +from langchain.agents import initialize_agent, AgentType |
| 81 | +from langchain_scrapegraph.tools import SmartscraperTool |
| 82 | +from langchain_openai import ChatOpenAI |
| 83 | + |
| 84 | +# Initialize tools |
| 85 | +tools = [ |
| 86 | + SmartscraperTool(), |
| 87 | +] |
| 88 | + |
| 89 | +# Create an agent |
| 90 | +agent = initialize_agent( |
| 91 | + tools=tools, |
| 92 | + llm=ChatOpenAI(temperature=0), |
| 93 | + agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, |
| 94 | + verbose=True |
| 95 | +) |
| 96 | + |
| 97 | +# Use the agent |
| 98 | +response = agent.run(""" |
| 99 | + Visit example.com, make a summary of the content and extract the main heading and first paragraph |
| 100 | +""") |
| 101 | +``` |
| 102 | + |
| 103 | +## ⚙️ Configuration |
| 104 | + |
| 105 | +Set your ScrapeGraph API key in your environment: |
| 106 | +```bash |
| 107 | +export SGAI_API_KEY="your-api-key-here" |
| 108 | +``` |
| 109 | + |
| 110 | +Or set it programmatically: |
| 111 | +```python |
| 112 | +import os |
| 113 | +os.environ["SGAI_API_KEY"] = "your-api-key-here" |
| 114 | +``` |
| 115 | + |
| 116 | +## 📚 Documentation |
| 117 | + |
| 118 | +- [API Documentation](https://scrapegraphai.com/docs) |
| 119 | +- [LangChain Documentation](https://python.langchain.com/docs/get_started/introduction.html) |
| 120 | +- [Examples](examples/) |
| 121 | + |
| 122 | +## 💬 Support & Feedback |
| 123 | + |
| 124 | + |
| 125 | +- 💻 GitHub Issues: [Create an issue](https://github.com/ScrapeGraphAI/langchain-scrapegraph/issues) |
| 126 | +- 🌟 Feature Requests: [Request a feature](https://github.com/ScrapeGraphAI/langchain-scrapegraph/issues/new) |
| 127 | + |
| 128 | +## 📄 License |
| 129 | + |
| 130 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 131 | + |
| 132 | +## 🙏 Acknowledgments |
| 133 | + |
| 134 | +This project is built on top of: |
| 135 | +- [LangChain](https://github.com/langchain-ai/langchain) |
| 136 | +- [ScrapeGraph AI](https://scrapegraphai.com) |
| 137 | + |
| 138 | +--- |
| 139 | + |
| 140 | +Made with ❤️ by [ScrapeGraph AI](https://scrapegraphai.com) |
0 commit comments