Have you ever imagined a tool that could understand your intentions and automatically execute complex web data extraction tasks? ScrapeGraphAI is precisely that tool, leveraging cutting-edge artificial intelligence technology to make data extraction unprecedentedly simple and efficient.
Introducing ScrapeGraphAI: The Future of Web Scraping
ScrapeGraphAI is an innovative Python library designed for web scraping that utilizes Large Language Models (LLMs) and direct graphs to create scraping pipelines for websites, documents, and XML files. Its groundbreaking approach allows users to simply describe the information they want to extract, and the tool does the rest!
Key Features
- User-Friendly: With just an API key, you can scrape thousands of web pages in seconds.
- Streamlined Development: Implement your project with minimal code, saving valuable time and resources.
- Business-Focused: By automating the technical aspects, ScrapeGraphAI allows you to concentrate on your core business objectives.
Getting Started with ScrapeGraphAI
Online Demonstrations
For those who want to see ScrapeGraphAI in action before diving in, there are two excellent online demonstrations available:
- Official Streamlit Demo: Experience the tool’s capabilities firsthand at https://scrapegraph-ai-demo.streamlit.app/
- Google Colab Notebook: Explore and experiment with ScrapeGraphAI in a interactive Jupyter environment at https://colab.research.google.com/drive/1sEZBonBMGP44CtO6GQTwAlL0BGJXjtfd
Local Installation
To set up ScrapeGraphAI on your local machine, follow these steps:
- Install the library using pip:
pip install scrapegraphai
- For scraping client-side rendered (JavaScript-generated) web pages, you’ll also need to install Playwright:
playwright install
Playwright is a powerful Python library that automates Chromium, Firefox, WebKit, and other major browsers with a single API, making it an essential companion to ScrapeGraphAI for comprehensive web scraping capabilities.
Harnessing the Power of ScrapeGraphAI
ScrapeGraphAI offers flexibility in its use of Large Language Models (LLMs), supporting various APIs including OpenAI, Groq, Azure, and Gemini. For those preferring local models, it also integrates with Ollama.
Built-in Scraping Workflows
The library comes with three pre-configured web scraping workflows to suit different needs:
- SmartScraperGraph: A single-page scraping tool that only requires user prompts and an input source.
- SearchGraph: A multi-page scraping tool that extracts information from the top ‘n’ search engine results.
- SpeechGraph: A single-page scraping tool that extracts information from websites and generates audio files.
Practical Examples
To illustrate the versatility and power of ScrapeGraphAI, let’s explore several implementation examples using different LLM APIs and configurations.
Example 1: Using Ollama API
from scrapegraphai.graphs import SmartScraperGraph
graph_config = {
"llm": {
"model": "ollama/mistral",
"temperature": 0,
"format": "json",
"base_url": "http://localhost:11434",
},
"embeddings": {
"model": "ollama/nomic-embed-text",
"base_url": "http://localhost:11434",
}
}
smart_scraper_graph = SmartScraperGraph(
prompt="List me all the articles",
source="https://perinim.github.io/projects",
config=graph_config
)
result = smart_scraper_graph.run()
print(result)
Example 2: Leveraging ChatGPT API
from scrapegraphai.graphs import SmartScraperGraph
OPENAI_API_KEY = "YOUR_API_KEY"
graph_config = {
"llm": {
"api_key": OPENAI_API_KEY,
"model": "gpt-3.5-turbo",
},
}
smart_scraper_graph = SmartScraperGraph(
prompt="List me all the articles",
source="https://perinim.github.io/projects",
config=graph_config
)
result = smart_scraper_graph.run()
print(result)
Example 3: Utilizing Groq API
from scrapegraphai.graphs import SmartScraperGraph
from scrapegraphai.utils import prettify_exec_info
import os
groq_key = os.getenv("GROQ_APIKEY")
graph_config = {
"llm": {
"model": "groq/gemma-7b-it",
"api_key": groq_key,
"temperature": 0
},
"embeddings": {
"model": "ollama/nomic-embed-text",
"temperature": 0,
"base_url": "http://localhost:11434",
},
"headless": False
}
smart_scraper_graph = SmartScraperGraph(
prompt="List me all the projects with their description and the author.",
source="https://perinim.github.io/projects",
config=graph_config
)
result = smart_scraper_graph.run()
print(result)
Example 4: Implementing Gemini API
from scrapegraphai.graphs import SmartScraperGraph
GOOGLE_APIKEY = "YOUR_API_KEY"
graph_config = {
"llm": {
"api_key": GOOGLE_APIKEY,
"model": "gemini-pro",
},
}
smart_scraper_graph = SmartScraperGraph(
prompt="List me all the articles",
source="https://perinim.github.io/projects",
config=graph_config
)
result = smart_scraper_graph.run()
print(result)
Example 5: Docker Integration for Local Models
For those preferring to use local models, ScrapeGraphAI can be integrated with Docker. Here’s how to set it up:
- Create and start the Docker container:
docker-compose up -d
docker exec -it ollama ollama pull stablelm-zephyr
- Implement the scraping:
from scrapegraphai.graphs import SmartScraperGraph
graph_config = {
"llm": {
"model": "ollama/mistral",
"temperature": 0,
"format": "json",
},
}
smart_scraper_graph = SmartScraperGraph(
prompt="List me all the articles",
source="https://perinim.github.io/projects",
config=graph_config
)
result = smart_scraper_graph.run()
print(result)
The Future of AI-Powered Web Scraping
As AI technology continues to evolve, it presents both opportunities and challenges for traditional tools. ScrapeGraphAI represents a significant leap forward in making web scraping more accessible and efficient. We can expect to see an increasing number of intelligent tools emerging in this space, further revolutionizing how we extract and process data from the web.
By combining the power of AI with web scraping techniques, ScrapeGraphAI opens up new possibilities for businesses, researchers, and developers to gather and analyze data more effectively than ever before. As the tool continues to develop and improve, it has the potential to become an indispensable asset for anyone working with web data, from small startups to large enterprises.
For those interested in exploring ScrapeGraphAI further, the official documentation provides comprehensive guidance and additional examples. As with any powerful tool, it’s important to use ScrapeGraphAI responsibly and in compliance with website terms of service and relevant data protection laws.