This repository contains examples of using the ScrapeGraphAI platform for web scraping with AI-powered capabilities.
ScrapeGraphAI is a powerful platform that combines web scraping with AI processing to extract meaningful data from websites. This demo shows two approaches:
- Using the Python Library - Direct integration with the
scrapegraphai
library - Using the API - Interaction through the
scrapegraph_py
client
This example demonstrates using the ScrapeGraphAI library directly to scrape news from Wired.com:
from scrapegraphai.graphs import SmartScraperGraph
smart_scraper_graph = SmartScraperGraph(
prompt="Give me all the news",
source="https://www.wired.com/",
config=graph_config,
)
result = smart_scraper_graph.run()
This example shows how to use the ScrapeGraphAI API client to extract product information from Amazon:
from scrapegraph_py import Client
sgai_client = Client()
response = sgai_client.smartscraper(
website_url="https://www.amazon.it/s?k=keyboard",
user_prompt="Extract the names and prices of all keyboards",
)
- Clone this repository
- Create a virtual environment:
python -m venv .venv
- Activate the virtual environment:
- Windows:
.venv\Scripts\activate
- macOS/Linux:
source .venv/bin/activate
- Windows:
- Install dependencies:
pip install -r requirements.txt
- Copy
.env.example
to.env
and add your API keys - Run an example:
python scraping_library.py
orpython scraping_api.py
- Python 3.8+
- ScrapeGraphAI API key
- OpenAI API key (for certain models)
MIT