mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-07-09 21:19:20 +08:00
docs: improved readme + fix csv scraper imports
This commit is contained in:
parent
0b582bea66
commit
14b4b19f60
@ -3,9 +3,9 @@ Basic example of scraping pipeline using CSVScraperMultiGraph from CSV documents
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pandas as pd
|
|
||||||
from scrapegraphai.graphs import CSVScraperMultiGraph
|
from scrapegraphai.graphs import CSVScraperMultiGraph
|
||||||
from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info
|
from scrapegraphai.utils import prettify_exec_info
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
# Read the CSV file
|
# Read the CSV file
|
||||||
@ -15,7 +15,8 @@ FILE_NAME = "inputs/username.csv"
|
|||||||
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
file_path = os.path.join(curr_dir, FILE_NAME)
|
file_path = os.path.join(curr_dir, FILE_NAME)
|
||||||
|
|
||||||
text = pd.read_csv(file_path)
|
with open(file_path, "r") as file:
|
||||||
|
text = file.read()
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
# Define the configuration for the graph
|
# Define the configuration for the graph
|
||||||
@ -44,7 +45,7 @@ graph_config = {
|
|||||||
csv_scraper_graph = CSVScraperMultiGraph(
|
csv_scraper_graph = CSVScraperMultiGraph(
|
||||||
prompt="List me all the last names",
|
prompt="List me all the last names",
|
||||||
source=[str(text), str(text)],
|
source=[str(text), str(text)],
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = csv_scraper_graph.run()
|
result = csv_scraper_graph.run()
|
||||||
@ -56,7 +57,3 @@ print(result)
|
|||||||
|
|
||||||
graph_exec_info = csv_scraper_graph.get_execution_info()
|
graph_exec_info = csv_scraper_graph.get_execution_info()
|
||||||
print(prettify_exec_info(graph_exec_info))
|
print(prettify_exec_info(graph_exec_info))
|
||||||
|
|
||||||
# Save to json or csv
|
|
||||||
convert_to_csv(result, "result")
|
|
||||||
convert_to_json(result, "result")
|
|
||||||
|
|||||||
@ -3,9 +3,9 @@ Basic example of scraping pipeline using CSVScraperGraph from CSV documents
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pandas as pd
|
|
||||||
from scrapegraphai.graphs import CSVScraperGraph
|
from scrapegraphai.graphs import CSVScraperGraph
|
||||||
from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info
|
from scrapegraphai.utils import prettify_exec_info
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
# Read the CSV file
|
# Read the CSV file
|
||||||
@ -15,7 +15,8 @@ FILE_NAME = "inputs/username.csv"
|
|||||||
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
file_path = os.path.join(curr_dir, FILE_NAME)
|
file_path = os.path.join(curr_dir, FILE_NAME)
|
||||||
|
|
||||||
text = pd.read_csv(file_path)
|
with open(file_path, "r") as file:
|
||||||
|
text = file.read()
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
# Define the configuration for the graph
|
# Define the configuration for the graph
|
||||||
@ -44,7 +45,7 @@ graph_config = {
|
|||||||
csv_scraper_graph = CSVScraperGraph(
|
csv_scraper_graph = CSVScraperGraph(
|
||||||
prompt="List me all the last names",
|
prompt="List me all the last names",
|
||||||
source=str(text), # Pass the content of the file, not the file object
|
source=str(text), # Pass the content of the file, not the file object
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = csv_scraper_graph.run()
|
result = csv_scraper_graph.run()
|
||||||
@ -56,7 +57,3 @@ print(result)
|
|||||||
|
|
||||||
graph_exec_info = csv_scraper_graph.get_execution_info()
|
graph_exec_info = csv_scraper_graph.get_execution_info()
|
||||||
print(prettify_exec_info(graph_exec_info))
|
print(prettify_exec_info(graph_exec_info))
|
||||||
|
|
||||||
# Save to json or csv
|
|
||||||
convert_to_csv(result, "result")
|
|
||||||
convert_to_json(result, "result")
|
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
"""
|
"""
|
||||||
Basic example of scraping pipeline using CSVScraperMultiGraph from CSV documents
|
Basic example of scraping pipeline using CSVScraperMultiGraph from CSV documents
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import pandas as pd
|
|
||||||
from scrapegraphai.graphs import CSVScraperMultiGraph
|
from scrapegraphai.graphs import CSVScraperMultiGraph
|
||||||
from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info
|
from scrapegraphai.utils import prettify_exec_info
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
# ************************************************
|
# ************************************************
|
||||||
@ -16,7 +18,8 @@ FILE_NAME = "inputs/username.csv"
|
|||||||
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
file_path = os.path.join(curr_dir, FILE_NAME)
|
file_path = os.path.join(curr_dir, FILE_NAME)
|
||||||
|
|
||||||
text = pd.read_csv(file_path)
|
with open(file_path, "r") as file:
|
||||||
|
text = file.read()
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
# Define the configuration for the graph
|
# Define the configuration for the graph
|
||||||
@ -24,7 +27,7 @@ text = pd.read_csv(file_path)
|
|||||||
openai_key = os.getenv("OPENAI_APIKEY")
|
openai_key = os.getenv("OPENAI_APIKEY")
|
||||||
|
|
||||||
graph_config = {
|
graph_config = {
|
||||||
"llm": {
|
"llm": {
|
||||||
"api_key": openai_key,
|
"api_key": openai_key,
|
||||||
"model": "openai/gpt-4o",
|
"model": "openai/gpt-4o",
|
||||||
},
|
},
|
||||||
@ -37,7 +40,7 @@ graph_config = {
|
|||||||
csv_scraper_graph = CSVScraperMultiGraph(
|
csv_scraper_graph = CSVScraperMultiGraph(
|
||||||
prompt="List me all the last names",
|
prompt="List me all the last names",
|
||||||
source=[str(text), str(text)],
|
source=[str(text), str(text)],
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = csv_scraper_graph.run()
|
result = csv_scraper_graph.run()
|
||||||
@ -49,7 +52,3 @@ print(result)
|
|||||||
|
|
||||||
graph_exec_info = csv_scraper_graph.get_execution_info()
|
graph_exec_info = csv_scraper_graph.get_execution_info()
|
||||||
print(prettify_exec_info(graph_exec_info))
|
print(prettify_exec_info(graph_exec_info))
|
||||||
|
|
||||||
# Save to json or csv
|
|
||||||
convert_to_csv(result, "result")
|
|
||||||
convert_to_json(result, "result")
|
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
"""
|
"""
|
||||||
Basic example of scraping pipeline using CSVScraperGraph from CSV documents
|
Basic example of scraping pipeline using CSVScraperGraph from CSV documents
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import pandas as pd
|
|
||||||
from scrapegraphai.graphs import CSVScraperGraph
|
from scrapegraphai.graphs import CSVScraperGraph
|
||||||
from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info
|
from scrapegraphai.utils import prettify_exec_info
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
@ -17,7 +19,8 @@ FILE_NAME = "inputs/username.csv"
|
|||||||
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
file_path = os.path.join(curr_dir, FILE_NAME)
|
file_path = os.path.join(curr_dir, FILE_NAME)
|
||||||
|
|
||||||
text = pd.read_csv(file_path)
|
with open(file_path, "r") as file:
|
||||||
|
text = file.read()
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
# Define the configuration for the graph
|
# Define the configuration for the graph
|
||||||
@ -39,7 +42,7 @@ graph_config = {
|
|||||||
csv_scraper_graph = CSVScraperGraph(
|
csv_scraper_graph = CSVScraperGraph(
|
||||||
prompt="List me all the last names",
|
prompt="List me all the last names",
|
||||||
source=str(text), # Pass the content of the file, not the file object
|
source=str(text), # Pass the content of the file, not the file object
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = csv_scraper_graph.run()
|
result = csv_scraper_graph.run()
|
||||||
@ -51,7 +54,3 @@ print(result)
|
|||||||
|
|
||||||
graph_exec_info = csv_scraper_graph.get_execution_info()
|
graph_exec_info = csv_scraper_graph.get_execution_info()
|
||||||
print(prettify_exec_info(graph_exec_info))
|
print(prettify_exec_info(graph_exec_info))
|
||||||
|
|
||||||
# Save to json or csv
|
|
||||||
convert_to_csv(result, "result")
|
|
||||||
convert_to_json(result, "result")
|
|
||||||
|
|||||||
@ -1,32 +1,62 @@
|
|||||||
# Scrapegraph-ai Examples
|
# 🕷️ Scrapegraph-ai Examples
|
||||||
|
|
||||||
This directory contains various example implementations of Scrapegraph-ai for different use cases.
|
This directory contains various example implementations of Scrapegraph-ai for different use cases. Each example demonstrates how to leverage the power of Scrapegraph-ai for specific scenarios.
|
||||||
|
|
||||||
If you want more specific examples, visit [this](https://github.com/ScrapeGraphAI/ScrapegraphLib-Examples).
|
> **Note:** While these examples showcase implementations using OpenAI and Ollama, Scrapegraph-ai supports many other LLM providers! Check out our [documentation](https://docs-oss.scrapegraphai.com/examples) for the full list of supported providers.
|
||||||
|
|
||||||
## Available Examples
|
## 📚 Available Examples
|
||||||
|
|
||||||
- `smart_scraper/` - Advanced web scraping with intelligent content extraction
|
- 🧠 `smart_scraper/` - Advanced web scraping with intelligent content extraction
|
||||||
- `depth_search_graph/` - Deep web crawling and content exploration
|
- 🔎 `search_graph/` - Web search and data retrieval
|
||||||
- `csv_scraper_graph/` - Scraping and processing data into CSV format
|
- ⚙️ `script_generator_graph/` - Automated script generation
|
||||||
- `xml_scraper_graph/` - XML data extraction and processing
|
- 🌐 `depth_search_graph/` - Deep web crawling and content exploration
|
||||||
- `speech_graph/` - Speech processing and analysis
|
- 📊 `csv_scraper_graph/` - Scraping and processing data into CSV format
|
||||||
- `omni_scraper_graph/` - Universal web scraping for multiple data types
|
- 📑 `xml_scraper_graph/` - XML data extraction and processing
|
||||||
- `omni_search_graph/` - Comprehensive search across multiple sources
|
- 🎤 `speech_graph/` - Speech processing and analysis
|
||||||
- `document_scraper_graph/` - Document parsing and data extraction
|
- 🔄 `omni_scraper_graph/` - Universal web scraping for multiple data types
|
||||||
- `script_generator_graph/` - Automated script generation
|
- 🔍 `omni_search_graph/` - Comprehensive search across multiple sources
|
||||||
- `custom_graph/` - Custom graph implementation examples
|
- 📄 `document_scraper_graph/` - Document parsing and data extraction
|
||||||
- `code_generator_graph/` - Code generation utilities
|
- 🛠️ `custom_graph/` - Custom graph implementation examples
|
||||||
- `json_scraper_graph/` - JSON data extraction and processing
|
- 💻 `code_generator_graph/` - Code generation utilities
|
||||||
- `search_graph/` - Web search and data retrieval
|
- 📋 `json_scraper_graph/` - JSON data extraction and processing
|
||||||
|
|
||||||
## Getting Started
|
## 🚀 Getting Started
|
||||||
|
|
||||||
1. Choose the example that best fits your use case
|
1. Choose the example that best fits your use case
|
||||||
2. Navigate to the corresponding directory
|
2. Navigate to the corresponding directory
|
||||||
3. Follow the README instructions in each directory
|
3. Follow the README instructions in each directory
|
||||||
4. Configure any required environment variables using the provided `.env.example` files
|
4. Configure any required environment variables using the provided `.env.example` files
|
||||||
|
|
||||||
## Requirements
|
## ⚡ Quick Setup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install scrapegraphai
|
||||||
|
|
||||||
|
playwright install
|
||||||
|
|
||||||
|
# choose an example
|
||||||
|
cd examples/smart_scraper_graph/openai
|
||||||
|
|
||||||
|
# run the example
|
||||||
|
python smart_scraper_openai.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📋 Requirements
|
||||||
|
|
||||||
Each example may have its own specific requirements. Please refer to the individual README files in each directory for detailed setup instructions.
|
Each example may have its own specific requirements. Please refer to the individual README files in each directory for detailed setup instructions.
|
||||||
|
|
||||||
|
## 📚 Additional Resources
|
||||||
|
|
||||||
|
- 📖 [Full Documentation](https://docs-oss.scrapegraphai.com/examples)
|
||||||
|
- 💡 [Examples Repository](https://github.com/ScrapeGraphAI/ScrapegraphLib-Examples)
|
||||||
|
- 🤝 [Community Support](https://github.com/ScrapeGraphAI/scrapegraph-ai/discussions)
|
||||||
|
|
||||||
|
## 🤔 Need Help?
|
||||||
|
|
||||||
|
- Check out our [documentation](https://docs-oss.scrapegraphai.com)
|
||||||
|
- Join our [Discord community](https://discord.gg/scrapegraphai)
|
||||||
|
- Open an [issue](https://github.com/ScrapeGraphAI/scrapegraph-ai/issues)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
⭐ Don't forget to star our repository if you find these examples helpful!
|
||||||
|
|||||||
@ -2,7 +2,9 @@
|
|||||||
Basic example of scraping pipeline using SmartScraper
|
Basic example of scraping pipeline using SmartScraper
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperLiteGraph
|
from scrapegraphai.graphs import SmartScraperLiteGraph
|
||||||
from scrapegraphai.utils import prettify_exec_info
|
from scrapegraphai.utils import prettify_exec_info
|
||||||
|
|
||||||
@ -14,13 +16,13 @@ graph_config = {
|
|||||||
"base_url": "http://localhost:11434",
|
"base_url": "http://localhost:11434",
|
||||||
},
|
},
|
||||||
"verbose": True,
|
"verbose": True,
|
||||||
"headless": False
|
"headless": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
smart_scraper_lite_graph = SmartScraperLiteGraph(
|
smart_scraper_lite_graph = SmartScraperLiteGraph(
|
||||||
prompt="Who is Marco Perini?",
|
prompt="Who is Marco Perini?",
|
||||||
source="https://perinim.github.io/",
|
source="https://perinim.github.io/",
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = smart_scraper_lite_graph.run()
|
result = smart_scraper_lite_graph.run()
|
||||||
@ -2,9 +2,10 @@
|
|||||||
Basic example of scraping pipeline using SmartScraper
|
Basic example of scraping pipeline using SmartScraper
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperMultiConcatGraph
|
from scrapegraphai.graphs import SmartScraperMultiConcatGraph
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@ -18,10 +19,10 @@ graph_config = {
|
|||||||
"model": "ollama/llama3.1",
|
"model": "ollama/llama3.1",
|
||||||
"temperature": 0,
|
"temperature": 0,
|
||||||
"format": "json", # Ollama needs the format to be specified explicitly
|
"format": "json", # Ollama needs the format to be specified explicitly
|
||||||
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
|
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
|
||||||
},
|
},
|
||||||
"verbose": True,
|
"verbose": True,
|
||||||
"headless": False
|
"headless": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
# *******************************************************
|
# *******************************************************
|
||||||
@ -30,12 +31,9 @@ graph_config = {
|
|||||||
|
|
||||||
multiple_search_graph = SmartScraperMultiConcatGraph(
|
multiple_search_graph = SmartScraperMultiConcatGraph(
|
||||||
prompt="Who is Marco Perini?",
|
prompt="Who is Marco Perini?",
|
||||||
source= [
|
source=["https://perinim.github.io/", "https://perinim.github.io/cv/"],
|
||||||
"https://perinim.github.io/",
|
|
||||||
"https://perinim.github.io/cv/"
|
|
||||||
],
|
|
||||||
schema=None,
|
schema=None,
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = multiple_search_graph.run()
|
result = multiple_search_graph.run()
|
||||||
@ -1,7 +1,9 @@
|
|||||||
"""
|
"""
|
||||||
Basic example of scraping pipeline using SmartScraper
|
Basic example of scraping pipeline using SmartScraper
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperMultiLiteGraph
|
from scrapegraphai.graphs import SmartScraperMultiLiteGraph
|
||||||
from scrapegraphai.utils import prettify_exec_info
|
from scrapegraphai.utils import prettify_exec_info
|
||||||
|
|
||||||
@ -17,7 +19,7 @@ graph_config = {
|
|||||||
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
|
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
|
||||||
},
|
},
|
||||||
"verbose": True,
|
"verbose": True,
|
||||||
"headless": False
|
"headless": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
@ -26,11 +28,8 @@ graph_config = {
|
|||||||
|
|
||||||
smart_scraper_multi_lite_graph = SmartScraperMultiLiteGraph(
|
smart_scraper_multi_lite_graph = SmartScraperMultiLiteGraph(
|
||||||
prompt="Who is Marco Perini?",
|
prompt="Who is Marco Perini?",
|
||||||
source= [
|
source=["https://perinim.github.io/", "https://perinim.github.io/cv/"],
|
||||||
"https://perinim.github.io/",
|
config=graph_config,
|
||||||
"https://perinim.github.io/cv/"
|
|
||||||
],
|
|
||||||
config=graph_config
|
|
||||||
)
|
)
|
||||||
|
|
||||||
result = smart_scraper_multi_lite_graph.run()
|
result = smart_scraper_multi_lite_graph.run()
|
||||||
@ -42,4 +41,3 @@ print(json.dumps(result, indent=4))
|
|||||||
|
|
||||||
graph_exec_info = smart_scraper_multi_lite_graph.get_execution_info()
|
graph_exec_info = smart_scraper_multi_lite_graph.get_execution_info()
|
||||||
print(prettify_exec_info(graph_exec_info))
|
print(prettify_exec_info(graph_exec_info))
|
||||||
|
|
||||||
@ -3,6 +3,7 @@ Basic example of scraping pipeline using SmartScraper
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperMultiGraph
|
from scrapegraphai.graphs import SmartScraperMultiGraph
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
@ -15,9 +16,8 @@ graph_config = {
|
|||||||
"format": "json", # Ollama needs the format to be specified explicitly
|
"format": "json", # Ollama needs the format to be specified explicitly
|
||||||
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
|
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
|
||||||
},
|
},
|
||||||
|
|
||||||
"verbose": True,
|
"verbose": True,
|
||||||
"headless": False
|
"headless": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -27,12 +27,9 @@ graph_config = {
|
|||||||
|
|
||||||
multiple_search_graph = SmartScraperMultiGraph(
|
multiple_search_graph = SmartScraperMultiGraph(
|
||||||
prompt="Who is Marco Perini?",
|
prompt="Who is Marco Perini?",
|
||||||
source= [
|
source=["https://perinim.github.io/", "https://perinim.github.io/cv/"],
|
||||||
"https://perinim.github.io/",
|
|
||||||
"https://perinim.github.io/cv/"
|
|
||||||
],
|
|
||||||
schema=None,
|
schema=None,
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = multiple_search_graph.run()
|
result = multiple_search_graph.run()
|
||||||
@ -1,12 +1,16 @@
|
|||||||
"""
|
"""
|
||||||
Basic example of scraping pipeline using SmartScraper with schema
|
Basic example of scraping pipeline using SmartScraper with schema
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperGraph
|
from scrapegraphai.graphs import SmartScraperGraph
|
||||||
from scrapegraphai.utils import prettify_exec_info
|
from scrapegraphai.utils import prettify_exec_info
|
||||||
|
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
# Define the configuration for the graph
|
# Define the configuration for the graph
|
||||||
# ************************************************
|
# ************************************************
|
||||||
@ -14,9 +18,11 @@ class Project(BaseModel):
|
|||||||
title: str = Field(description="The title of the project")
|
title: str = Field(description="The title of the project")
|
||||||
description: str = Field(description="The description of the project")
|
description: str = Field(description="The description of the project")
|
||||||
|
|
||||||
|
|
||||||
class Projects(BaseModel):
|
class Projects(BaseModel):
|
||||||
projects: List[Project]
|
projects: List[Project]
|
||||||
|
|
||||||
|
|
||||||
graph_config = {
|
graph_config = {
|
||||||
"llm": {
|
"llm": {
|
||||||
"model": "ollama/llama3.1",
|
"model": "ollama/llama3.1",
|
||||||
@ -25,7 +31,7 @@ graph_config = {
|
|||||||
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
|
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
|
||||||
},
|
},
|
||||||
"verbose": True,
|
"verbose": True,
|
||||||
"headless": False
|
"headless": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
@ -36,8 +42,15 @@ smart_scraper_graph = SmartScraperGraph(
|
|||||||
prompt="List me all the projects with their description",
|
prompt="List me all the projects with their description",
|
||||||
source="https://perinim.github.io/projects/",
|
source="https://perinim.github.io/projects/",
|
||||||
schema=Projects,
|
schema=Projects,
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = smart_scraper_graph.run()
|
result = smart_scraper_graph.run()
|
||||||
print(json.dumps(result, indent=4))
|
print(json.dumps(result, indent=4))
|
||||||
|
|
||||||
|
# ************************************************
|
||||||
|
# Get graph execution info
|
||||||
|
# ************************************************
|
||||||
|
|
||||||
|
graph_exec_info = smart_scraper_graph.get_execution_info()
|
||||||
|
print(prettify_exec_info(graph_exec_info))
|
||||||
@ -1,9 +1,12 @@
|
|||||||
"""
|
"""
|
||||||
Basic example of scraping pipeline using SmartScraper
|
Basic example of scraping pipeline using SmartScraper
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperLiteGraph
|
from scrapegraphai.graphs import SmartScraperLiteGraph
|
||||||
from scrapegraphai.utils import prettify_exec_info
|
from scrapegraphai.utils import prettify_exec_info
|
||||||
|
|
||||||
@ -21,7 +24,7 @@ graph_config = {
|
|||||||
smart_scraper_lite_graph = SmartScraperLiteGraph(
|
smart_scraper_lite_graph = SmartScraperLiteGraph(
|
||||||
prompt="Who is Marco Perini?",
|
prompt="Who is Marco Perini?",
|
||||||
source="https://perinim.github.io/",
|
source="https://perinim.github.io/",
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = smart_scraper_lite_graph.run()
|
result = smart_scraper_lite_graph.run()
|
||||||
@ -29,4 +32,3 @@ print(json.dumps(result, indent=4))
|
|||||||
|
|
||||||
graph_exec_info = smart_scraper_lite_graph.get_execution_info()
|
graph_exec_info = smart_scraper_lite_graph.get_execution_info()
|
||||||
print(prettify_exec_info(graph_exec_info))
|
print(prettify_exec_info(graph_exec_info))
|
||||||
|
|
||||||
@ -1,9 +1,12 @@
|
|||||||
"""
|
"""
|
||||||
Basic example of scraping pipeline using SmartScraper
|
Basic example of scraping pipeline using SmartScraper
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperMultiConcatGraph
|
from scrapegraphai.graphs import SmartScraperMultiConcatGraph
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@ -28,12 +31,9 @@ graph_config = {
|
|||||||
|
|
||||||
multiple_search_graph = SmartScraperMultiConcatGraph(
|
multiple_search_graph = SmartScraperMultiConcatGraph(
|
||||||
prompt="Who is Marco Perini?",
|
prompt="Who is Marco Perini?",
|
||||||
source= [
|
source=["https://perinim.github.io/", "https://perinim.github.io/cv/"],
|
||||||
"https://perinim.github.io/",
|
|
||||||
"https://perinim.github.io/cv/"
|
|
||||||
],
|
|
||||||
schema=None,
|
schema=None,
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = multiple_search_graph.run()
|
result = multiple_search_graph.run()
|
||||||
@ -1,9 +1,12 @@
|
|||||||
"""
|
"""
|
||||||
Basic example of scraping pipeline using SmartScraper
|
Basic example of scraping pipeline using SmartScraper
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperMultiLiteGraph
|
from scrapegraphai.graphs import SmartScraperMultiLiteGraph
|
||||||
from scrapegraphai.utils import prettify_exec_info
|
from scrapegraphai.utils import prettify_exec_info
|
||||||
|
|
||||||
@ -29,11 +32,8 @@ graph_config = {
|
|||||||
|
|
||||||
smart_scraper_multi_lite_graph = SmartScraperMultiLiteGraph(
|
smart_scraper_multi_lite_graph = SmartScraperMultiLiteGraph(
|
||||||
prompt="Who is Marco Perini?",
|
prompt="Who is Marco Perini?",
|
||||||
source= [
|
source=["https://perinim.github.io/", "https://perinim.github.io/cv/"],
|
||||||
"https://perinim.github.io/",
|
config=graph_config,
|
||||||
"https://perinim.github.io/cv/"
|
|
||||||
],
|
|
||||||
config=graph_config
|
|
||||||
)
|
)
|
||||||
|
|
||||||
result = smart_scraper_multi_lite_graph.run()
|
result = smart_scraper_multi_lite_graph.run()
|
||||||
@ -1,9 +1,12 @@
|
|||||||
"""
|
"""
|
||||||
Basic example of scraping pipeline using SmartScraper
|
Basic example of scraping pipeline using SmartScraper
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperMultiGraph
|
from scrapegraphai.graphs import SmartScraperMultiGraph
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@ -29,12 +32,9 @@ graph_config = {
|
|||||||
|
|
||||||
multiple_search_graph = SmartScraperMultiGraph(
|
multiple_search_graph = SmartScraperMultiGraph(
|
||||||
prompt="Who is Marco Perini?",
|
prompt="Who is Marco Perini?",
|
||||||
source= [
|
source=["https://perinim.github.io/", "https://perinim.github.io/cv/"],
|
||||||
"https://perinim.github.io/",
|
|
||||||
"https://perinim.github.io/cv/"
|
|
||||||
],
|
|
||||||
schema=None,
|
schema=None,
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = multiple_search_graph.run()
|
result = multiple_search_graph.run()
|
||||||
@ -1,10 +1,13 @@
|
|||||||
"""
|
"""
|
||||||
Basic example of scraping pipeline using SmartScraper with schema
|
Basic example of scraping pipeline using SmartScraper with schema
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from scrapegraphai.graphs import SmartScraperGraph
|
from scrapegraphai.graphs import SmartScraperGraph
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@ -13,13 +16,16 @@ load_dotenv()
|
|||||||
# Define the output schema for the graph
|
# Define the output schema for the graph
|
||||||
# ************************************************
|
# ************************************************
|
||||||
|
|
||||||
|
|
||||||
class Project(BaseModel):
|
class Project(BaseModel):
|
||||||
title: str = Field(description="The title of the project")
|
title: str = Field(description="The title of the project")
|
||||||
description: str = Field(description="The description of the project")
|
description: str = Field(description="The description of the project")
|
||||||
|
|
||||||
|
|
||||||
class Projects(BaseModel):
|
class Projects(BaseModel):
|
||||||
projects: List[Project]
|
projects: List[Project]
|
||||||
|
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
# Define the configuration for the graph
|
# Define the configuration for the graph
|
||||||
# ************************************************
|
# ************************************************
|
||||||
@ -43,7 +49,7 @@ smart_scraper_graph = SmartScraperGraph(
|
|||||||
prompt="List me all the projects with their description",
|
prompt="List me all the projects with their description",
|
||||||
source="https://perinim.github.io/projects/",
|
source="https://perinim.github.io/projects/",
|
||||||
schema=Projects,
|
schema=Projects,
|
||||||
config=graph_config
|
config=graph_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = smart_scraper_graph.run()
|
result = smart_scraper_graph.run()
|
||||||
Loading…
Reference in New Issue
Block a user