Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
refactoring examples
Marco Vinciguerra0b582bea661e
diff --git a/examples/code_generator_graph/.env.example b/examples/code_generator_graph/.env.examplenew file mode 100644index 00000000..a93912e4--- /dev/null+++ b/examples/code_generator_graph/.env.example@@ -0,0 +1,14 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# Code Generator Settings+DEFAULT_LANGUAGE=python+GENERATE_TESTS=true+ADD_DOCUMENTATION=true+CODE_STYLE=pep8+TYPE_CHECKING=true\ No newline at end of filediff --git a/examples/code_generator_graph/README.md b/examples/code_generator_graph/README.mdnew file mode 100644index 00000000..bc4b5dec--- /dev/null+++ b/examples/code_generator_graph/README.md@@ -0,0 +1,30 @@+# Code Generator Graph Example++This example demonstrates how to use Scrapegraph-ai to generate code based on specifications and requirements.++## Features++- Code generation from specifications+- Multiple programming languages support+- Code documentation+- Best practices implementation++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import CodeGeneratorGraph++graph = CodeGeneratorGraph()+code = graph.generate("code specification")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/code_generator_graph/ollama/code_generator_graph_ollama.py b/examples/code_generator_graph/ollama/code_generator_graph_ollama.pynew file mode 100644index 00000000..46ab8ab3--- /dev/null+++ b/examples/code_generator_graph/ollama/code_generator_graph_ollama.py@@ -0,0 +1,61 @@+"""+Basic example of scraping pipeline using Code Generator with schema+"""++import json+from typing import List+from dotenv import load_dotenv+from pydantic import BaseModel, Field+from scrapegraphai.graphs import CodeGeneratorGraph++load_dotenv()++# ************************************************+# Define the output schema for the graph+# ************************************************++class Project(BaseModel):+ title: str = Field(description="The title of the project")+ description: str = Field(description="The description of the project")++class Projects(BaseModel):+ projects: List[Project]++# ************************************************+# Define the configuration for the graph+# ************************************************+++graph_config = {+ "llm": {+ "model": "ollama/llama3",+ "temperature": 0,+ "format": "json",+ "base_url": "http://localhost:11434",+ },+ "verbose": True,+ "headless": False,+ "reduction": 2,+ "max_iterations": {+ "overall": 10,+ "syntax": 3,+ "execution": 3,+ "validation": 3,+ "semantic": 3+ },+ "output_file_name": "extracted_data.py"+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++code_generator_graph = CodeGeneratorGraph(+ prompt="List me all the projects with their description",+ source="https://perinim.github.io/projects/",+ schema=Projects,+ config=graph_config+)++result = code_generator_graph.run()+print(result)\ No newline at end of filediff --git a/examples/code_generator_graph/openai/code_generator_graph_openai.py b/examples/code_generator_graph/openai/code_generator_graph_openai.pynew file mode 100644index 00000000..a9a2ea56--- /dev/null+++ b/examples/code_generator_graph/openai/code_generator_graph_openai.py@@ -0,0 +1,59 @@+"""+Basic example of scraping pipeline using Code Generator with schema+"""+import os+from typing import List+from dotenv import load_dotenv+from pydantic import BaseModel, Field+from scrapegraphai.graphs import CodeGeneratorGraph++load_dotenv()++# ************************************************+# Define the output schema for the graph+# ************************************************++class Project(BaseModel):+ title: str = Field(description="The title of the project")+ description: str = Field(description="The description of the project")++class Projects(BaseModel):+ projects: List[Project]++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key":openai_key,+ "model": "openai/gpt-4o-mini",+ },+ "verbose": True,+ "headless": False,+ "reduction": 2,+ "max_iterations": {+ "overall": 10,+ "syntax": 3,+ "execution": 3,+ "validation": 3,+ "semantic": 3+ },+ "output_file_name": "extracted_data.py"+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++code_generator_graph = CodeGeneratorGraph(+ prompt="List me all the projects with their description",+ source="https://perinim.github.io/projects/",+ schema=Projects,+ config=graph_config+)++result = code_generator_graph.run()+print(result)diff --git a/examples/csv_scraper_graph/.env.example b/examples/csv_scraper_graph/.env.examplenew file mode 100644index 00000000..1917f9aa--- /dev/null+++ b/examples/csv_scraper_graph/.env.example@@ -0,0 +1,11 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# CSV Scraper Settings+CSV_DELIMITER=,+MAX_ROWS=1000\ No newline at end of filediff --git a/examples/csv_scraper_graph/README.md b/examples/csv_scraper_graph/README.mdnew file mode 100644index 00000000..d39858b0--- /dev/null+++ b/examples/csv_scraper_graph/README.md@@ -0,0 +1,30 @@+# CSV Scraper Graph Example++This example demonstrates how to use Scrapegraph-ai to extract data from web sources and save it in CSV format.++## Features++- Table data extraction+- CSV formatting+- Data cleaning+- Structured output++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import CsvScraperGraph++graph = CsvScraperGraph()+csv_data = graph.scrape("https://example.com/table")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/csv_scraper_graph/ollama/csv_scraper_graph_multi_ollama.py b/examples/csv_scraper_graph/ollama/csv_scraper_graph_multi_ollama.pynew file mode 100644index 00000000..fb6bce51--- /dev/null+++ b/examples/csv_scraper_graph/ollama/csv_scraper_graph_multi_ollama.py@@ -0,0 +1,62 @@+"""+Basic example of scraping pipeline using CSVScraperMultiGraph from CSV documents+"""++import os+import pandas as pd+from scrapegraphai.graphs import CSVScraperMultiGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Read the CSV file+# ************************************************++FILE_NAME = "inputs/username.csv"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++text = pd.read_csv(file_path)++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/llama3",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ # "model_tokens": 2000, # set context length arbitrarily+ "base_url": "http://localhost:11434",+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ "base_url": "http://localhost:11434",+ },+ "verbose": True,+}++# ************************************************+# Create the CSVScraperMultiGraph instance and run it+# ************************************************++csv_scraper_graph = CSVScraperMultiGraph(+ prompt="List me all the last names",+ source=[str(text), str(text)],+ config=graph_config+)++result = csv_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = csv_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/csv_scraper_graph/ollama/csv_scraper_ollama.py b/examples/csv_scraper_graph/ollama/csv_scraper_ollama.pynew file mode 100644index 00000000..8d1edbd7--- /dev/null+++ b/examples/csv_scraper_graph/ollama/csv_scraper_ollama.py@@ -0,0 +1,62 @@+"""+Basic example of scraping pipeline using CSVScraperGraph from CSV documents+"""++import os+import pandas as pd+from scrapegraphai.graphs import CSVScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Read the CSV file+# ************************************************++FILE_NAME = "inputs/username.csv"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++text = pd.read_csv(file_path)++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/llama3",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ # "model_tokens": 2000, # set context length arbitrarily+ "base_url": "http://localhost:11434",+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ "base_url": "http://localhost:11434",+ },+ "verbose": True,+}++# ************************************************+# Create the CSVScraperGraph instance and run it+# ************************************************++csv_scraper_graph = CSVScraperGraph(+ prompt="List me all the last names",+ source=str(text), # Pass the content of the file, not the file object+ config=graph_config+)++result = csv_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = csv_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/csv_scraper_graph/ollama/inputs/username.csv b/examples/csv_scraper_graph/ollama/inputs/username.csvnew file mode 100644index 00000000..006ac8e6--- /dev/null+++ b/examples/csv_scraper_graph/ollama/inputs/username.csv@@ -0,0 +1,7 @@+Username; Identifier;First name;Last name+booker12;9012;Rachel;Booker+grey07;2070;Laura;Grey+johnson81;4081;Craig;Johnson+jenkins46;9346;Mary;Jenkins+smith79;5079;Jamie;Smith+diff --git a/examples/anthropic/csv_scraper_graph_multi_anthropic.py b/examples/csv_scraper_graph/openai/csv_scraper_graph_multi_openai.pysimilarity index 77%rename from examples/anthropic/csv_scraper_graph_multi_anthropic.pyrename to examples/csv_scraper_graph/openai/csv_scraper_graph_multi_openai.pyindex ed0bcbc5..6ed33c90 100644--- a/examples/anthropic/csv_scraper_graph_multi_anthropic.py+++ b/examples/csv_scraper_graph/openai/csv_scraper_graph_multi_openai.py@@ -3,8 +3,9 @@ Basic example of scraping pipeline using CSVScraperMultiGraph from CSV documents"""import osfrom dotenv import load_dotenv+import pandas as pdfrom scrapegraphai.graphs import CSVScraperMultiGraph-from scrapegraphai.utils import prettify_exec_info+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_infoload_dotenv()# ************************************************@@ -15,17 +16,17 @@ FILE_NAME = "inputs/username.csv"curr_dir = os.path.dirname(os.path.realpath(__file__))file_path = os.path.join(curr_dir, FILE_NAME)-with open(file_path, 'r') as file:- text = file.read()+text = pd.read_csv(file_path)# ************************************************# Define the configuration for the graph# ************************************************+openai_key = os.getenv("OPENAI_APIKEY")graph_config = {- "llm": {- "api_key": os.getenv("ANTHROPIC_API_KEY"),- "model": "anthropic/claude-3-haiku-20240307",+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",},}@@ -48,3 +49,7 @@ print(result)graph_exec_info = csv_scraper_graph.get_execution_info()print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/anthropic/csv_scraper_anthropic.py b/examples/csv_scraper_graph/openai/csv_scraper_openai.pysimilarity index 71%rename from examples/anthropic/csv_scraper_anthropic.pyrename to examples/csv_scraper_graph/openai/csv_scraper_openai.pyindex 4fd5aaaf..d9527b86 100644--- a/examples/anthropic/csv_scraper_anthropic.py+++ b/examples/csv_scraper_graph/openai/csv_scraper_openai.py@@ -3,8 +3,9 @@ Basic example of scraping pipeline using CSVScraperGraph from CSV documents"""import osfrom dotenv import load_dotenv+import pandas as pdfrom scrapegraphai.graphs import CSVScraperGraph-from scrapegraphai.utils import prettify_exec_info+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_infoload_dotenv()@@ -16,22 +17,18 @@ FILE_NAME = "inputs/username.csv"curr_dir = os.path.dirname(os.path.realpath(__file__))file_path = os.path.join(curr_dir, FILE_NAME)-with open(file_path, 'r') as file:- text = file.read()+text = pd.read_csv(file_path)# ************************************************# Define the configuration for the graph# ************************************************-# required environment variables in .env-# HUGGINGFACEHUB_API_TOKEN-# ANTHROPIC_API_KEY-load_dotenv()+openai_key = os.getenv("OPENAI_APIKEY")graph_config = {"llm": {- "api_key": os.getenv("ANTHROPIC_API_KEY"),- "model": "anthropic/claude-3-haiku-20240307",+ "api_key": openai_key,+ "model": "openai/gpt-4o",},}@@ -41,7 +38,7 @@ graph_config = {csv_scraper_graph = CSVScraperGraph(prompt="List me all the last names",- source=text, # Pass the content of the file+ source=str(text), # Pass the content of the file, not the file objectconfig=graph_config)@@ -53,4 +50,8 @@ print(result)# ************************************************graph_exec_info = csv_scraper_graph.get_execution_info()-print(prettify_exec_info(graph_exec_info))\ No newline at end of file+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/csv_scraper_graph/openai/inputs/username.csv b/examples/csv_scraper_graph/openai/inputs/username.csvnew file mode 100644index 00000000..006ac8e6--- /dev/null+++ b/examples/csv_scraper_graph/openai/inputs/username.csv@@ -0,0 +1,7 @@+Username; Identifier;First name;Last name+booker12;9012;Rachel;Booker+grey07;2070;Laura;Grey+johnson81;4081;Craig;Johnson+jenkins46;9346;Mary;Jenkins+smith79;5079;Jamie;Smith+diff --git a/examples/custom_graph/.env.example b/examples/custom_graph/.env.examplenew file mode 100644index 00000000..9eac4cb8--- /dev/null+++ b/examples/custom_graph/.env.example@@ -0,0 +1,13 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# Custom Graph Settings+CUSTOM_NODE_TIMEOUT=30+MAX_NODES=10+DEBUG_MODE=false+LOG_LEVEL=info\ No newline at end of filediff --git a/examples/custom_graph/README.md b/examples/custom_graph/README.mdnew file mode 100644index 00000000..e6d3b88a--- /dev/null+++ b/examples/custom_graph/README.md@@ -0,0 +1,31 @@+# Custom Graph Example++This example demonstrates how to create and implement custom graphs using Scrapegraph-ai.++## Features++- Custom node creation+- Graph customization+- Pipeline configuration+- Custom data processing++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import CustomGraph++graph = CustomGraph()+graph.add_node("custom_node", CustomNode())+results = graph.process()+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/custom_graph/ollama/custom_graph_ollama.py b/examples/custom_graph/ollama/custom_graph_ollama.pynew file mode 100644index 00000000..c505d068--- /dev/null+++ b/examples/custom_graph/ollama/custom_graph_ollama.py@@ -0,0 +1,101 @@+"""+Example of custom graph using existing nodes+"""++import os+from langchain_openai import OpenAIEmbeddings+from langchain_openai import ChatOpenAI+from scrapegraphai.graphs import BaseGraph+from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode, RobotsNode++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/mistral",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ # "model_tokens": 2000, # set context length arbitrarily+ "base_url": "http://localhost:11434",+ },++ "verbose": True,+}++# ************************************************+# Define the graph nodes+# ************************************************++llm_model = ChatOpenAI(graph_config["llm"])+embedder = OpenAIEmbeddings(api_key=llm_model.openai_api_key)++# define the nodes for the graph+robot_node = RobotsNode(+ input="url",+ output=["is_scrapable"],+ node_config={+ "llm_model": llm_model,+ "force_scraping": True,+ "verbose": True,+ }+)++fetch_node = FetchNode(+ input="url | local_dir",+ output=["doc"],+ node_config={+ "verbose": True,+ "headless": True,+ }+)+parse_node = ParseNode(+ input="doc",+ output=["parsed_doc"],+ node_config={+ "chunk_size": 4096,+ "verbose": True,+ }+)++generate_answer_node = GenerateAnswerNode(+ input="user_prompt & (relevant_chunks | parsed_doc | doc)",+ output=["answer"],+ node_config={+ "llm_model": llm_model,+ "verbose": True,+ }+)++# ************************************************+# Create the graph by defining the connections+# ************************************************++graph = BaseGraph(+ nodes=[+ robot_node,+ fetch_node,+ parse_node,+ generate_answer_node,+ ],+ edges=[+ (robot_node, fetch_node),+ (fetch_node, parse_node),+ (parse_node, generate_answer_node)+ ],+ entry_point=robot_node+)++# ************************************************+# Execute the graph+# ************************************************++result, execution_info = graph.execute({+ "user_prompt": "Describe the content",+ "url": "https://example.com/"+})++# get the answer from the result+result = result.get("answer", "No answer found.")+print(result)diff --git a/examples/custom_graph/openai/custom_graph_openai.py b/examples/custom_graph/openai/custom_graph_openai.pynew file mode 100644index 00000000..00fecfdd--- /dev/null+++ b/examples/custom_graph/openai/custom_graph_openai.py@@ -0,0 +1,109 @@+"""+Example of custom graph using existing nodes+"""+import os+from dotenv import load_dotenv+from langchain_openai import OpenAIEmbeddings+from langchain_openai import ChatOpenAI+from scrapegraphai.graphs import BaseGraph+from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode, RobotsNode++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")+graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "gpt-4o",+ },+}++# ************************************************+# Define the graph nodes+# ************************************************++llm_model = ChatOpenAI(graph_config["llm"])+embedder = OpenAIEmbeddings(api_key=llm_model.openai_api_key)++# define the nodes for the graph+robot_node = RobotsNode(+ input="url",+ output=["is_scrapable"],+ node_config={+ "llm_model": llm_model,+ "force_scraping": True,+ "verbose": True,+ }+)++fetch_node = FetchNode(+ input="url | local_dir",+ output=["doc"],+ node_config={+ "verbose": True,+ "headless": True,+ }+)+parse_node = ParseNode(+ input="doc",+ output=["parsed_doc"],+ node_config={+ "chunk_size": 4096,+ "verbose": True,+ }+)+rag_node = RAGNode(+ input="user_prompt & (parsed_doc | doc)",+ output=["relevant_chunks"],+ node_config={+ "llm_model": llm_model,+ "embedder_model": embedder,+ "verbose": True,+ }+)+generate_answer_node = GenerateAnswerNode(+ input="user_prompt & (relevant_chunks | parsed_doc | doc)",+ output=["answer"],+ node_config={+ "llm_model": llm_model,+ "verbose": True,+ }+)++# ************************************************+# Create the graph by defining the connections+# ************************************************++graph = BaseGraph(+ nodes=[+ robot_node,+ fetch_node,+ parse_node,+ rag_node,+ generate_answer_node,+ ],+ edges=[+ (robot_node, fetch_node),+ (fetch_node, parse_node),+ (parse_node, rag_node),+ (rag_node, generate_answer_node)+ ],+ entry_point=robot_node+)++# ************************************************+# Execute the graph+# ************************************************++result, execution_info = graph.execute({+ "user_prompt": "Describe the content",+ "url": "https://example.com/"+})++# get the answer from the result+result = result.get("answer", "No answer found.")+print(result)diff --git a/examples/depth_search_graph/.env.example b/examples/depth_search_graph/.env.examplenew file mode 100644index 00000000..8c10cfbb--- /dev/null+++ b/examples/depth_search_graph/.env.example@@ -0,0 +1,14 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# Depth Search Settings+MAX_DEPTH=5+CRAWL_DELAY=1+RESPECT_ROBOTS_TXT=true+MAX_PAGES_PER_DOMAIN=100+USER_AGENT=Mozilla/5.0\ No newline at end of filediff --git a/examples/depth_search_graph/README.md b/examples/depth_search_graph/README.mdnew file mode 100644index 00000000..c4ce05df--- /dev/null+++ b/examples/depth_search_graph/README.md@@ -0,0 +1,30 @@+# Depth Search Graph Example++This example demonstrates how to use Scrapegraph-ai for deep web crawling and content exploration.++## Features++- Deep web crawling+- Content discovery+- Link analysis+- Recursive search++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import DepthSearchGraph++graph = DepthSearchGraph()+results = graph.search("https://example.com", depth=3)+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/depth_search_graph/ollama/depth_search_graph_ollama.py b/examples/depth_search_graph/ollama/depth_search_graph_ollama.pynew file mode 100644index 00000000..d0f960b5--- /dev/null+++ b/examples/depth_search_graph/ollama/depth_search_graph_ollama.py@@ -0,0 +1,32 @@+"""+depth_search_graph_opeani example+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import DepthSearchGraph++load_dotenv()++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "model": "ollama/llama3.1",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "verbose": True,+ "headless": False,+ "depth": 2,+ "only_inside_links": False,+}++search_graph = DepthSearchGraph(+ prompt="List me all the projects with their description",+ source="https://perinim.github.io",+ config=graph_config+)++result = search_graph.run()+print(result)diff --git a/examples/openai/depth_search_graph_openai.py b/examples/depth_search_graph/openai/depth_search_graph_openai.pysimilarity index 100%rename from examples/openai/depth_search_graph_openai.pyrename to examples/depth_search_graph/openai/depth_search_graph_openai.pydiff --git a/examples/document_scraper_graph/.env.example b/examples/document_scraper_graph/.env.examplenew file mode 100644index 00000000..2e7bab46--- /dev/null+++ b/examples/document_scraper_graph/.env.example@@ -0,0 +1,13 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# Document Scraper Settings+OCR_ENABLED=true+EXTRACT_METADATA=true+MAX_FILE_SIZE=10485760 # 10MB+SUPPORTED_FORMATS=pdf,doc,docx,txt\ No newline at end of filediff --git a/examples/document_scraper_graph/README.md b/examples/document_scraper_graph/README.mdnew file mode 100644index 00000000..f8561ee7--- /dev/null+++ b/examples/document_scraper_graph/README.md@@ -0,0 +1,30 @@+# Document Scraper Graph Example++This example demonstrates how to use Scrapegraph-ai to extract data from various document formats (PDF, DOC, DOCX, etc.).++## Features++- Multi-format document support+- Text extraction+- Document parsing+- Metadata extraction++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import DocumentScraperGraph++graph = DocumentScraperGraph()+content = graph.scrape("document.pdf")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/document_scraper_graph/ollama/document_scraper_ollama.py b/examples/document_scraper_graph/ollama/document_scraper_ollama.pynew file mode 100644index 00000000..6853a549--- /dev/null+++ b/examples/document_scraper_graph/ollama/document_scraper_ollama.py@@ -0,0 +1,42 @@+"""+document_scraper example+"""+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import DocumentScraperGraph++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************+graph_config = {+ "llm": {+ "model": "ollama/llama3",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ "model_tokens": 4000,+ },+ "verbose": True,+ "headless": False,+}++source = """+ The Divine Comedy, Italian La Divina Commedia, original name La commedia, long narrative poem written in Italian+ circa 1308/21 by Dante. It is usually held to be one of the world s great works of literature.+ Divided into three major sections—Inferno, Purgatorio, and Paradiso—the narrative traces the journey of Dante+ from darkness and error to the revelation of the divine light, culminating in the Beatific Vision of God.+ Dante is guided by the Roman poet Virgil, who represents the epitome of human knowledge, from the dark wood+ through the descending circles of the pit of Hell (Inferno). He then climbs the mountain of Purgatory, guided+ by the Roman poet Statius, who represents the fulfilment of human knowledge, and is finally led by his lifelong love,+ the Beatrice of his earlier poetry, through the celestial spheres of Paradise.+"""++pdf_scraper_graph = DocumentScraperGraph(+ prompt="Summarize the text and find the main topics",+ source=source,+ config=graph_config,+)+result = pdf_scraper_graph.run()++print(json.dumps(result, indent=4))diff --git a/examples/document_scraper_graph/ollama/inputs/plain_html_example.txt b/examples/document_scraper_graph/ollama/inputs/plain_html_example.txtnew file mode 100644index 00000000..78f814ae--- /dev/null+++ b/examples/document_scraper_graph/ollama/inputs/plain_html_example.txt@@ -0,0 +1,105 @@+<body class="fixed-top-nav " style="padding-top: 57px;">+ <header>+ <nav id="navbar" class="navbar navbar-light navbar-expand-sm fixed-top">+ <div class="container">+ <a class="navbar-brand title font-weight-lighter" href="/"><span class="font-weight-bold">Marco </span>Perini</a> <button class="navbar-toggler collapsed ml-auto" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar top-bar"></span> <span class="icon-bar middle-bar"></span> <span class="icon-bar bottom-bar"></span> </button>+ <div class="collapse navbar-collapse text-right" id="navbarNav">+ <ul class="navbar-nav ml-auto flex-nowrap">+ <li class="nav-item "> <a class="nav-link" href="/">About</a> </li>+ <li class="nav-item dropdown active">+ <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Projects<span class="sr-only">(current)</span></a>+ <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">+ <a class="dropdown-item" href="/projects/">Projects</a>+ <div class="dropdown-divider"></div>+ <a class="dropdown-item" href="/competitions/">Competitions</a>+ </div>+ </li>+ <li class="nav-item "> <a class="nav-link" href="/cv/">CV</a> </li>+ <li class="toggle-container"> <button id="light-toggle" title="Change theme"> <i class="fa-solid fa-moon"></i> <i class="fa-solid fa-sun"></i> </button> </li>+ </ul>+ </div>+ </div>+ </nav>+ <progress id="progress" value="0" max="284" style="top: 57px;">+ <div class="progress-container"> <span class="progress-bar"></span> </div>+ </progress>+ </header>+ <div class="container mt-5">+ <div class="post">+ <header class="post-header">+ <h1 class="post-title">Projects</h1>+ <p class="post-description"></p>+ </header>+ <article>+ <div class="projects">+ <div class="grid" style="position: relative; height: 861.992px;">+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 0px; top: 0px;">+ <a href="/projects/rotary-pendulum-rl/">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/rotary_pybullet.jpg" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Rotary Pendulum RL</h4>+ <p class="card-text">Open Source project aimed at controlling a real life rotary pendulum using RL algorithms</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 260px; top: 0px;">+ <a href="https://github.com/PeriniM/DQN-SwingUp" rel="external nofollow noopener" target="_blank">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/value-policy-heatmaps.jpg" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">DQN Implementation from scratch</h4>+ <p class="card-text">Developed a Deep Q-Network algorithm to train a simple and double pendulum</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 0px; top: 447.414px;">+ <a href="https://github.com/PeriniM/Multi-Agents-HAED" rel="external nofollow noopener" target="_blank">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/multi_agents_haed.gif" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Multi Agents HAED</h4>+ <p class="card-text">University project which focuses on simulating a multi-agent system to perform environment mapping. Agents, equipped with sensors, explore and record their surroundings, considering uncertainties in their readings.</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 260px; top: 370.172px;">+ <a href="/projects/wireless-esc-drone/">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/wireless_esc.gif" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Wireless ESC for Modular Drones</h4>+ <p class="card-text">Modular drone architecture proposal and proof of concept. The project received maximum grade.</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ </div>+ </div>+ </article>+ </div>+ </div>+ <footer class="fixed-bottom">+ <div class="container mt-0"> © Copyright 2023 Marco Perini. Powered by <a href="https://jekyllrb.com/" target="_blank" rel="external nofollow noopener">Jekyll</a> with <a href="https://github.com/alshedivat/al-folio" rel="external nofollow noopener" target="_blank">al-folio</a> theme. Hosted by <a href="https://pages.github.com/" target="_blank" rel="external nofollow noopener">GitHub Pages</a>. </div>+ </footer>+ <div class="hiddendiv common"></div>+</body>\ No newline at end of filediff --git a/examples/document_scraper_graph/openai/document_scraper_openai.py b/examples/document_scraper_graph/openai/document_scraper_openai.pynew file mode 100644index 00000000..f9475446--- /dev/null+++ b/examples/document_scraper_graph/openai/document_scraper_openai.py@@ -0,0 +1,39 @@+"""+document_scraper example+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import DocumentScraperGraph++load_dotenv()+++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ }+}++source = """+ The Divine Comedy, Italian La Divina Commedia, original name La commedia, long narrative poem written in Italian+ circa 1308/21 by Dante. It is usually held to be one of the world s great works of literature.+ Divided into three major sections—Inferno, Purgatorio, and Paradiso—the narrative traces the journey of Dante+ from darkness and error to the revelation of the divine light, culminating in the Beatific Vision of God.+ Dante is guided by the Roman poet Virgil, who represents the epitome of human knowledge, from the dark wood+ through the descending circles of the pit of Hell (Inferno). He then climbs the mountain of Purgatory, guided+ by the Roman poet Statius, who represents the fulfilment of human knowledge, and is finally led by his lifelong love,+ the Beatrice of his earlier poetry, through the celestial spheres of Paradise.+"""++pdf_scraper_graph = DocumentScraperGraph(+ prompt="Summarize the text and find the main topics",+ source=source,+ config=graph_config,+)+result = pdf_scraper_graph.run()++print(json.dumps(result, indent=4))\ No newline at end of filediff --git a/examples/document_scraper_graph/openai/inputs/markdown_example.md b/examples/document_scraper_graph/openai/inputs/markdown_example.mdnew file mode 100644index 00000000..85088f29--- /dev/null+++ b/examples/document_scraper_graph/openai/inputs/markdown_example.md@@ -0,0 +1,35 @@+Marco Perini Toggle navigation++ * About+ * Projects(current)++Projects++Competitions++ * CV+ * ____++# Projects++ ++ ++ ++ ++© Copyright 2023 Marco Perini. Powered by Jekyll with+al-folio theme. Hosted by [GitHub+Pages](https://pages.github.com/).\ No newline at end of filediff --git a/examples/document_scraper_graph/openai/inputs/plain_html_example.txt b/examples/document_scraper_graph/openai/inputs/plain_html_example.txtnew file mode 100644index 00000000..78f814ae--- /dev/null+++ b/examples/document_scraper_graph/openai/inputs/plain_html_example.txt@@ -0,0 +1,105 @@+<body class="fixed-top-nav " style="padding-top: 57px;">+ <header>+ <nav id="navbar" class="navbar navbar-light navbar-expand-sm fixed-top">+ <div class="container">+ <a class="navbar-brand title font-weight-lighter" href="/"><span class="font-weight-bold">Marco </span>Perini</a> <button class="navbar-toggler collapsed ml-auto" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar top-bar"></span> <span class="icon-bar middle-bar"></span> <span class="icon-bar bottom-bar"></span> </button>+ <div class="collapse navbar-collapse text-right" id="navbarNav">+ <ul class="navbar-nav ml-auto flex-nowrap">+ <li class="nav-item "> <a class="nav-link" href="/">About</a> </li>+ <li class="nav-item dropdown active">+ <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Projects<span class="sr-only">(current)</span></a>+ <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">+ <a class="dropdown-item" href="/projects/">Projects</a>+ <div class="dropdown-divider"></div>+ <a class="dropdown-item" href="/competitions/">Competitions</a>+ </div>+ </li>+ <li class="nav-item "> <a class="nav-link" href="/cv/">CV</a> </li>+ <li class="toggle-container"> <button id="light-toggle" title="Change theme"> <i class="fa-solid fa-moon"></i> <i class="fa-solid fa-sun"></i> </button> </li>+ </ul>+ </div>+ </div>+ </nav>+ <progress id="progress" value="0" max="284" style="top: 57px;">+ <div class="progress-container"> <span class="progress-bar"></span> </div>+ </progress>+ </header>+ <div class="container mt-5">+ <div class="post">+ <header class="post-header">+ <h1 class="post-title">Projects</h1>+ <p class="post-description"></p>+ </header>+ <article>+ <div class="projects">+ <div class="grid" style="position: relative; height: 861.992px;">+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 0px; top: 0px;">+ <a href="/projects/rotary-pendulum-rl/">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/rotary_pybullet.jpg" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Rotary Pendulum RL</h4>+ <p class="card-text">Open Source project aimed at controlling a real life rotary pendulum using RL algorithms</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 260px; top: 0px;">+ <a href="https://github.com/PeriniM/DQN-SwingUp" rel="external nofollow noopener" target="_blank">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/value-policy-heatmaps.jpg" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">DQN Implementation from scratch</h4>+ <p class="card-text">Developed a Deep Q-Network algorithm to train a simple and double pendulum</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 0px; top: 447.414px;">+ <a href="https://github.com/PeriniM/Multi-Agents-HAED" rel="external nofollow noopener" target="_blank">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/multi_agents_haed.gif" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Multi Agents HAED</h4>+ <p class="card-text">University project which focuses on simulating a multi-agent system to perform environment mapping. Agents, equipped with sensors, explore and record their surroundings, considering uncertainties in their readings.</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 260px; top: 370.172px;">+ <a href="/projects/wireless-esc-drone/">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/wireless_esc.gif" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Wireless ESC for Modular Drones</h4>+ <p class="card-text">Modular drone architecture proposal and proof of concept. The project received maximum grade.</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ </div>+ </div>+ </article>+ </div>+ </div>+ <footer class="fixed-bottom">+ <div class="container mt-0"> © Copyright 2023 Marco Perini. Powered by <a href="https://jekyllrb.com/" target="_blank" rel="external nofollow noopener">Jekyll</a> with <a href="https://github.com/alshedivat/al-folio" rel="external nofollow noopener" target="_blank">al-folio</a> theme. Hosted by <a href="https://pages.github.com/" target="_blank" rel="external nofollow noopener">GitHub Pages</a>. </div>+ </footer>+ <div class="hiddendiv common"></div>+</body>\ No newline at end of filediff --git a/examples/json_scraper_graph/.env.example b/examples/json_scraper_graph/.env.examplenew file mode 100644index 00000000..f1862149--- /dev/null+++ b/examples/json_scraper_graph/.env.example@@ -0,0 +1,11 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# JSON Scraper Settings+MAX_DEPTH=3+TIMEOUT=30\ No newline at end of filediff --git a/examples/json_scraper_graph/README.md b/examples/json_scraper_graph/README.mdnew file mode 100644index 00000000..217875ff--- /dev/null+++ b/examples/json_scraper_graph/README.md@@ -0,0 +1,30 @@+# JSON Scraper Graph Example++This example demonstrates how to use Scrapegraph-ai to extract and process JSON data from web sources.++## Features++- JSON data extraction+- Schema validation+- Data transformation+- Structured output++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import JsonScraperGraph++graph = JsonScraperGraph()+json_data = graph.scrape("https://api.example.com/data")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/json_scraper_graph/ollama/inputs/example.json b/examples/json_scraper_graph/ollama/inputs/example.jsonnew file mode 100644index 00000000..2263184c--- /dev/null+++ b/examples/json_scraper_graph/ollama/inputs/example.json@@ -0,0 +1,182 @@+{+ "kind":"youtube#searchListResponse",+ "etag":"q4ibjmYp1KA3RqMF4jFLl6PBwOg",+ "nextPageToken":"CAUQAA",+ "regionCode":"NL",+ "pageInfo":{+ "totalResults":1000000,+ "resultsPerPage":5+ },+ "items":[+ {+ "kind":"youtube#searchResult",+ "etag":"QCsHBifbaernVCbLv8Cu6rAeaDQ",+ "id":{+ "kind":"youtube#video",+ "videoId":"TvWDY4Mm5GM"+ },+ "snippet":{+ "publishedAt":"2023-07-24T14:15:01Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Football Clubs Kylian Mbappe Should Avoid Signing ✍️❌⚽️ #football #mbappe #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T14:15:01Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"0NG5QHdtIQM_V-DBJDEf-jK_Y9k",+ "id":{+ "kind":"youtube#video",+ "videoId":"aZM_42CcNZ4"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:09:27Z",+ "channelId":"UCM5gMM_HqfKHYIEJ3lstMUA",+ "title":"Which Football Club Could Cristiano Ronaldo Afford To Buy? 💰",+ "description":"Sign up to Sorare and get a FREE card: https://sorare.pxf.io/NellisShorts Give Soraredata a go for FREE: ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"John Nellis",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:09:27Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"WbBz4oh9I5VaYj91LjeJvffrBVY",+ "id":{+ "kind":"youtube#video",+ "videoId":"wkP3XS3aNAY"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:00:50Z",+ "channelId":"UC4EP1dxFDPup_aFLt0ElsDw",+ "title":"PAULO DYBALA vs THE WORLD'S LONGEST FREEKICK WALL",+ "description":"Can Paulo Dybala curl a football around the World's longest free kick wall? We met up with the World Cup winner and put him to ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Shoot for Love",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:00:50Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"juxv_FhT_l4qrR05S1QTrb4CGh8",+ "id":{+ "kind":"youtube#video",+ "videoId":"rJkDZ0WvfT8"+ },+ "snippet":{+ "publishedAt":"2023-07-24T10:00:39Z",+ "channelId":"UCO8qj5u80Ga7N_tP3BZWWhQ",+ "title":"TOP 10 DEFENDERS 2023",+ "description":"SoccerKingz https://soccerkingz.nl Use code: 'ILOVEHOF' to get 10% off. TOP 10 DEFENDERS 2023 Follow us! • Instagram ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Home of Football",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T10:00:39Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"wtuknXTmI1txoULeH3aWaOuXOow",+ "id":{+ "kind":"youtube#video",+ "videoId":"XH0rtu4U6SE"+ },+ "snippet":{+ "publishedAt":"2023-07-21T16:30:05Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Things You Didn't Know About Erling Haaland ⚽️🇳🇴 #football #haaland #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-21T16:30:05Z"+ }+ }+ ]+}\ No newline at end of filediff --git a/examples/json_scraper_graph/ollama/json_scraper_multi_ollama.py b/examples/json_scraper_graph/ollama/json_scraper_multi_ollama.pynew file mode 100644index 00000000..e80bf5ec--- /dev/null+++ b/examples/json_scraper_graph/ollama/json_scraper_multi_ollama.py@@ -0,0 +1,36 @@+"""+Module for showing how PDFScraper multi works+"""+import os+import json+from scrapegraphai.graphs import JSONScraperMultiGraph++graph_config = {+ "llm": {+ "model": "ollama/llama3",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ "model_tokens": 4000,+ },+ "verbose": True,+ "headless": False,+}++FILE_NAME = "inputs/example.json"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++sources = [text, text]++multiple_search_graph = JSONScraperMultiGraph(+ prompt= "List me all the authors, title and genres of the books",+ source= sources,+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/json_scraper_graph/ollama/json_scraper_ollama.py b/examples/json_scraper_graph/ollama/json_scraper_ollama.pynew file mode 100644index 00000000..ca4eb32e--- /dev/null+++ b/examples/json_scraper_graph/ollama/json_scraper_ollama.py@@ -0,0 +1,59 @@+"""+Basic example of scraping pipeline using JSONScraperGraph from JSON documents+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import JSONScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Read the JSON file+# ************************************************++FILE_NAME = "inputs/example.json"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/mistral",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ # "model_tokens": 2000, # set context length arbitrarily+ "base_url": "http://localhost:11434",+ },+ "verbose": True,+}++# ************************************************+# Create the JSONScraperGraph instance and run it+# ************************************************++json_scraper_graph = JSONScraperGraph(+ prompt="List me all the authors, title and genres of the books",+ source=text, # Pass the content of the file, not the file object+ config=graph_config+)++result = json_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = json_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/json_scraper_graph/openai/inputs/example.json b/examples/json_scraper_graph/openai/inputs/example.jsonnew file mode 100644index 00000000..2263184c--- /dev/null+++ b/examples/json_scraper_graph/openai/inputs/example.json@@ -0,0 +1,182 @@+{+ "kind":"youtube#searchListResponse",+ "etag":"q4ibjmYp1KA3RqMF4jFLl6PBwOg",+ "nextPageToken":"CAUQAA",+ "regionCode":"NL",+ "pageInfo":{+ "totalResults":1000000,+ "resultsPerPage":5+ },+ "items":[+ {+ "kind":"youtube#searchResult",+ "etag":"QCsHBifbaernVCbLv8Cu6rAeaDQ",+ "id":{+ "kind":"youtube#video",+ "videoId":"TvWDY4Mm5GM"+ },+ "snippet":{+ "publishedAt":"2023-07-24T14:15:01Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Football Clubs Kylian Mbappe Should Avoid Signing ✍️❌⚽️ #football #mbappe #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T14:15:01Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"0NG5QHdtIQM_V-DBJDEf-jK_Y9k",+ "id":{+ "kind":"youtube#video",+ "videoId":"aZM_42CcNZ4"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:09:27Z",+ "channelId":"UCM5gMM_HqfKHYIEJ3lstMUA",+ "title":"Which Football Club Could Cristiano Ronaldo Afford To Buy? 💰",+ "description":"Sign up to Sorare and get a FREE card: https://sorare.pxf.io/NellisShorts Give Soraredata a go for FREE: ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"John Nellis",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:09:27Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"WbBz4oh9I5VaYj91LjeJvffrBVY",+ "id":{+ "kind":"youtube#video",+ "videoId":"wkP3XS3aNAY"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:00:50Z",+ "channelId":"UC4EP1dxFDPup_aFLt0ElsDw",+ "title":"PAULO DYBALA vs THE WORLD'S LONGEST FREEKICK WALL",+ "description":"Can Paulo Dybala curl a football around the World's longest free kick wall? We met up with the World Cup winner and put him to ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Shoot for Love",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:00:50Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"juxv_FhT_l4qrR05S1QTrb4CGh8",+ "id":{+ "kind":"youtube#video",+ "videoId":"rJkDZ0WvfT8"+ },+ "snippet":{+ "publishedAt":"2023-07-24T10:00:39Z",+ "channelId":"UCO8qj5u80Ga7N_tP3BZWWhQ",+ "title":"TOP 10 DEFENDERS 2023",+ "description":"SoccerKingz https://soccerkingz.nl Use code: 'ILOVEHOF' to get 10% off. TOP 10 DEFENDERS 2023 Follow us! • Instagram ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Home of Football",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T10:00:39Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"wtuknXTmI1txoULeH3aWaOuXOow",+ "id":{+ "kind":"youtube#video",+ "videoId":"XH0rtu4U6SE"+ },+ "snippet":{+ "publishedAt":"2023-07-21T16:30:05Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Things You Didn't Know About Erling Haaland ⚽️🇳🇴 #football #haaland #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-21T16:30:05Z"+ }+ }+ ]+}\ No newline at end of filediff --git a/examples/json_scraper_graph/openai/json_scraper_multi_openai.py b/examples/json_scraper_graph/openai/json_scraper_multi_openai.pynew file mode 100644index 00000000..f7cb528a--- /dev/null+++ b/examples/json_scraper_graph/openai/json_scraper_multi_openai.py@@ -0,0 +1,37 @@+"""+Module for showing how PDFScraper multi works+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import JSONScraperMultiGraph++load_dotenv()++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ }+}++FILE_NAME = "inputs/example.json"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++sources = [text, text]++multiple_search_graph = JSONScraperMultiGraph(+ prompt= "List me all the authors, title and genres of the books",+ source= sources,+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/json_scraper_graph/openai/json_scraper_openai.py b/examples/json_scraper_graph/openai/json_scraper_openai.pynew file mode 100644index 00000000..891ec32a--- /dev/null+++ b/examples/json_scraper_graph/openai/json_scraper_openai.py@@ -0,0 +1,57 @@+"""+Basic example of scraping pipeline using JSONScraperGraph from JSON documents+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import JSONScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++load_dotenv()++# ************************************************+# Read the JSON file+# ************************************************++FILE_NAME = "inputs/example.json"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ },+}++# ************************************************+# Create the JSONScraperGraph instance and run it+# ************************************************++json_scraper_graph = JSONScraperGraph(+ prompt="List me all the authors, title and genres of the books",+ source=text, # Pass the content of the file, not the file object+ config=graph_config+)++result = json_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = json_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/json_scraper_graph/openai/md_scraper_openai.py b/examples/json_scraper_graph/openai/md_scraper_openai.pynew file mode 100644index 00000000..118e7d59--- /dev/null+++ b/examples/json_scraper_graph/openai/md_scraper_openai.py@@ -0,0 +1,57 @@+"""+Basic example of scraping pipeline using DocumentScraperGraph from MD documents+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import DocumentScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++load_dotenv()++# ************************************************+# Read the MD file+# ************************************************++FILE_NAME = "inputs/markdown_example.md"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ },+}++# ************************************************+# Create the DocumentScraperGraph instance and run it+# ************************************************++md_scraper_graph = DocumentScraperGraph(+ prompt="List me all the projects",+ source=text, # Pass the content of the file, not the file object+ config=graph_config+)++result = md_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = md_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/json_scraper_graph/openai/omni_scraper_openai.py b/examples/json_scraper_graph/openai/omni_scraper_openai.pynew file mode 100644index 00000000..61da3b6a--- /dev/null+++ b/examples/json_scraper_graph/openai/omni_scraper_openai.py@@ -0,0 +1,47 @@+"""+Basic example of scraping pipeline using OmniScraper+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import OmniScraperGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ },+ "verbose": True,+ "headless": True,+ "max_images": 5+}++# ************************************************+# Create the OmniScraperGraph instance and run it+# ************************************************++omni_scraper_graph = OmniScraperGraph(+ prompt="List me all the projects with their titles and image links and descriptions.",+ # also accepts a string with the already downloaded HTML code+ source="https://perinim.github.io/projects/",+ config=graph_config+)++result = omni_scraper_graph.run()+print(json.dumps(result, indent=2))++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = omni_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/omni_scraper_graph/.env.example b/examples/omni_scraper_graph/.env.examplenew file mode 100644index 00000000..d5bb1b4d--- /dev/null+++ b/examples/omni_scraper_graph/.env.example@@ -0,0 +1,13 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# Omni Scraper Settings+DEFAULT_FORMAT=auto+TIMEOUT=60+MAX_RETRIES=3+USER_AGENT=Mozilla/5.0\ No newline at end of filediff --git a/examples/omni_scraper_graph/README.md b/examples/omni_scraper_graph/README.mdnew file mode 100644index 00000000..da5ab652--- /dev/null+++ b/examples/omni_scraper_graph/README.md@@ -0,0 +1,30 @@+# Omni Scraper Graph Example++This example demonstrates how to use Scrapegraph-ai for universal web scraping across multiple data formats.++## Features++- Multi-format data extraction (JSON, XML, HTML, CSV)+- Automatic format detection+- Unified data output+- Content transformation++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import OmniScraperGraph++graph = OmniScraperGraph()+data = graph.scrape("https://example.com/data")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/omni_scraper_graph/omni_search_openai.py b/examples/omni_scraper_graph/omni_search_openai.pynew file mode 100644index 00000000..a6fdb266--- /dev/null+++ b/examples/omni_scraper_graph/omni_search_openai.py@@ -0,0 +1,45 @@+"""+Example of OmniSearchGraph+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import OmniSearchGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ },+ "max_results": 2,+ "max_images": 1,+ "verbose": True,+}++# ************************************************+# Create the OmniSearchGraph instance and run it+# ************************************************++omni_search_graph = OmniSearchGraph(+ prompt="List me all Chioggia's famous dishes and describe their pictures.",+ config=graph_config+)++result = omni_search_graph.run()+print(json.dumps(result, indent=2))++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = omni_search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/readme.md b/examples/readme.mdnew file mode 100644index 00000000..1d7b375f--- /dev/null+++ b/examples/readme.md@@ -0,0 +1,32 @@+# Scrapegraph-ai Examples++This directory contains various example implementations of Scrapegraph-ai for different use cases.++If you want more specific examples, visit [this](https://github.com/ScrapeGraphAI/ScrapegraphLib-Examples).++## Available Examples++- `smart_scraper/` - Advanced web scraping with intelligent content extraction+- `depth_search_graph/` - Deep web crawling and content exploration+- `csv_scraper_graph/` - Scraping and processing data into CSV format+- `xml_scraper_graph/` - XML data extraction and processing+- `speech_graph/` - Speech processing and analysis+- `omni_scraper_graph/` - Universal web scraping for multiple data types+- `omni_search_graph/` - Comprehensive search across multiple sources+- `document_scraper_graph/` - Document parsing and data extraction+- `script_generator_graph/` - Automated script generation+- `custom_graph/` - Custom graph implementation examples+- `code_generator_graph/` - Code generation utilities+- `json_scraper_graph/` - JSON data extraction and processing+- `search_graph/` - Web search and data retrieval++## Getting Started++1. Choose the example that best fits your use case+2. Navigate to the corresponding directory+3. Follow the README instructions in each directory+4. Configure any required environment variables using the provided `.env.example` files++## Requirements++Each example may have its own specific requirements. Please refer to the individual README files in each directory for detailed setup instructions.diff --git a/examples/script_generator_graph/.env.example b/examples/script_generator_graph/.env.examplenew file mode 100644index 00000000..216ab8a7--- /dev/null+++ b/examples/script_generator_graph/.env.example@@ -0,0 +1,13 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# Script Generator Settings+DEFAULT_LANGUAGE=python+INCLUDE_COMMENTS=true+ADD_TYPE_HINTS=true+CODE_STYLE=pep8\ No newline at end of filediff --git a/examples/script_generator_graph/README.md b/examples/script_generator_graph/README.mdnew file mode 100644index 00000000..7d1495c6--- /dev/null+++ b/examples/script_generator_graph/README.md@@ -0,0 +1,30 @@+# Script Generator Graph Example++This example demonstrates how to use Scrapegraph-ai to generate automation scripts based on data analysis.++## Features++- Automated script generation+- Task automation+- Code optimization+- Multiple language support++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import ScriptGeneratorGraph++graph = ScriptGeneratorGraph()+script = graph.generate("task description")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/script_generator_graph/ollama/script_generator_ollama.py b/examples/script_generator_graph/ollama/script_generator_ollama.pynew file mode 100644index 00000000..caa0455c--- /dev/null+++ b/examples/script_generator_graph/ollama/script_generator_ollama.py@@ -0,0 +1,40 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""+from scrapegraphai.graphs import ScriptCreatorGraph+from scrapegraphai.utils import prettify_exec_info+# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/llama3.1",+ "temperature": 0.5,+ # "model_tokens": 2000, # set context length arbitrarily,+ "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "library": "beautifoulsoup",+ "verbose": True,+}++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++smart_scraper_graph = ScriptCreatorGraph(+ prompt="List me all the news with their description.",+ # also accepts a string with the already downloaded HTML code+ source="https://perinim.github.io/projects",+ config=graph_config+)++result = smart_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = smart_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/script_generator_graph/ollama/script_multi_generator_ollama.py b/examples/script_generator_graph/ollama/script_multi_generator_ollama.pynew file mode 100644index 00000000..d94faba6--- /dev/null+++ b/examples/script_generator_graph/ollama/script_multi_generator_ollama.py@@ -0,0 +1,55 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import ScriptCreatorMultiGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/mistral",+ "temperature": 0,+ # "model_tokens": 2000, # set context length arbitrarily,+ "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "library": "beautifoulsoup",+ "verbose": True,+}++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++urls=[+ "https://schultzbergagency.com/emil-raste-karlsen/",+ "https://schultzbergagency.com/johanna-hedberg/",+]++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++script_creator_graph = ScriptCreatorMultiGraph(+ prompt="Find information about actors",+ # also accepts a string with the already downloaded HTML code+ source=urls,+ config=graph_config+)++result = script_creator_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = script_creator_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/script_generator_graph/openai/script_generator_multi_openai.py b/examples/script_generator_graph/openai/script_generator_multi_openai.pynew file mode 100644index 00000000..19eacf66--- /dev/null+++ b/examples/script_generator_graph/openai/script_generator_multi_openai.py@@ -0,0 +1,54 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import ScriptCreatorMultiGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ },+ "library": "beautifulsoup",+ "verbose": True,+}++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++urls=[+ "https://schultzbergagency.com/emil-raste-karlsen/",+ "https://schultzbergagency.com/johanna-hedberg/",+]++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++script_creator_graph = ScriptCreatorMultiGraph(+ prompt="Find information about actors",+ # also accepts a string with the already downloaded HTML code+ source=urls,+ config=graph_config+)++result = script_creator_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = script_creator_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/script_generator_graph/openai/script_generator_openai.py b/examples/script_generator_graph/openai/script_generator_openai.pynew file mode 100644index 00000000..611acc57--- /dev/null+++ b/examples/script_generator_graph/openai/script_generator_openai.py@@ -0,0 +1,46 @@+"""+Basic example of scraping pipeline using SmartScraper+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import ScriptCreatorGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************+++graph_config = {+ "llm": {+ "api_key": os.getenv("OPENAI_API_KEY"),+ "model": "openai/gpt-4o",+ },+ "library": "beautifulsoup",+ "verbose": True,+ "headless": False,+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_graph = ScriptCreatorGraph(+ prompt="List me all the news with their description.",+ # also accepts a string with the already downloaded HTML code+ source="https://perinim.github.io/projects",+ config=graph_config+)++result = smart_scraper_graph.run()+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))diff --git a/examples/script_generator_graph/openai/script_generator_schema_openai.py b/examples/script_generator_graph/openai/script_generator_schema_openai.pynew file mode 100644index 00000000..adb646d1--- /dev/null+++ b/examples/script_generator_graph/openai/script_generator_schema_openai.py@@ -0,0 +1,60 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""+import os+from typing import List+from dotenv import load_dotenv+from pydantic import BaseModel, Field+from scrapegraphai.graphs import ScriptCreatorGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the schema for the graph+# ************************************************++class Project(BaseModel):+ title: str = Field(description="The title of the project")+ description: str = Field(description="The description of the project")++class Projects(BaseModel):+ projects: List[Project]++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o"+ },+ "library": "beautifulsoup",+ "verbose": True,+}++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++script_creator_graph = ScriptCreatorGraph(+ prompt="List me all the projects with their description.",+ # also accepts a string with the already downloaded HTML code+ source="https://perinim.github.io/projects",+ config=graph_config,+ schema=Projects+)++result = script_creator_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = script_creator_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))+diff --git a/examples/search_graph/.env.example b/examples/search_graph/.env.examplenew file mode 100644index 00000000..a4b25c88--- /dev/null+++ b/examples/search_graph/.env.example@@ -0,0 +1,11 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Search API Configuration+SERP_API_KEY=your-serp-api-key-here++# Optional Configurations+MAX_SEARCH_RESULTS=10+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7\ No newline at end of filediff --git a/examples/search_graph/README.md b/examples/search_graph/README.mdnew file mode 100644index 00000000..084c6ea2--- /dev/null+++ b/examples/search_graph/README.md@@ -0,0 +1,31 @@+# Search Graph Example++This example shows how to implement a search graph for web content retrieval and analysis using Scrapegraph-ai.++## Features++- Web search integration+- Content relevance scoring+- Result filtering+- Data aggregation++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import SearchGraph++graph = SearchGraph()+results = graph.search("your search query")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key+- `SERP_API_KEY`: Your SERP API key (optional)\ No newline at end of filediff --git a/examples/search_graph/ollama/search_graph_ollama.py b/examples/search_graph/ollama/search_graph_ollama.pynew file mode 100644index 00000000..039ca00e--- /dev/null+++ b/examples/search_graph/ollama/search_graph_ollama.py@@ -0,0 +1,44 @@+"""+Example of Search Graph+"""+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************+++graph_config = {+ "llm": {+ "model": "ollama/llama3",+ "temperature": 0,+ # "format": "json", # Ollama needs the format to be specified explicitly+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "max_results": 5,+ "verbose": True,+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/search_graph/ollama/search_graph_schema_ollama.py b/examples/search_graph/ollama/search_graph_schema_ollama.pynew file mode 100644index 00000000..fb87954f--- /dev/null+++ b/examples/search_graph/ollama/search_graph_schema_ollama.py@@ -0,0 +1,58 @@+"""+Example of Search Graph+"""+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++from pydantic import BaseModel, Field+from typing import List++# ************************************************+# Define the output schema for the graph+# ************************************************++class Dish(BaseModel):+ name: str = Field(description="The name of the dish")+ description: str = Field(description="The description of the dish")++class Dishes(BaseModel):+ dishes: List[Dish]++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/mistral",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "verbose": True,+ "headless": False+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me Chioggia's famous dishes",+ config=graph_config,+ schema=Dishes+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/openai/search_graph_openai.py b/examples/search_graph/openai/search_graph_openai.pysimilarity index 100%rename from examples/openai/search_graph_openai.pyrename to examples/search_graph/openai/search_graph_openai.pydiff --git a/examples/search_graph/openai/search_graph_schema_openai.py b/examples/search_graph/openai/search_graph_schema_openai.pynew file mode 100644index 00000000..3109cc79--- /dev/null+++ b/examples/search_graph/openai/search_graph_schema_openai.py@@ -0,0 +1,61 @@+"""+Example of Search Graph+"""+import os+from typing import List+from dotenv import load_dotenv+from pydantic import BaseModel, Field+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++load_dotenv()++# ************************************************+# Define the output schema for the graph+# ************************************************++class Dish(BaseModel):+ name: str = Field(description="The name of the dish")+ description: str = Field(description="The description of the dish")++class Dishes(BaseModel):+ dishes: List[Dish]++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o"+ },+ "max_results": 2,+ "verbose": True,+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me Chioggia's famous dishes",+ config=graph_config,+ schema=Dishes+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/search_graph/openai/search_link_graph_openai.py b/examples/search_graph/openai/search_link_graph_openai.pynew file mode 100644index 00000000..f7436159--- /dev/null+++ b/examples/search_graph/openai/search_link_graph_openai.py@@ -0,0 +1,42 @@+"""+Basic example of scraping pipeline using SmartScraper+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchLinkGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()+# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ },+ "verbose": True,+ "headless": False,+}++# ************************************************+# Create the SearchLinkGraph instance and run it+# ************************************************++smart_scraper_graph = SearchLinkGraph(+ source="https://sport.sky.it/nba?gr=www",+ config=graph_config+)++result = smart_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = smart_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/smart_scraper/.env.example b/examples/smart_scraper/.env.examplenew file mode 100644index 00000000..7d2c49c0--- /dev/null+++ b/examples/smart_scraper/.env.example@@ -0,0 +1,7 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7\ No newline at end of filediff --git a/examples/smart_scraper/README.md b/examples/smart_scraper/README.mdnew file mode 100644index 00000000..ba4f638c--- /dev/null+++ b/examples/smart_scraper/README.md@@ -0,0 +1,30 @@+# Smart Scraper Example++This example demonstrates how to use Scrapegraph-ai for intelligent web scraping with automatic content detection and extraction.++## Features++- Intelligent content detection+- Automatic data extraction+- Content classification+- Clean data output++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your OpenAI API key in the `.env` file++## Usage++```python+from scrapegraphai.graphs import SmartScraperGraph++graph = SmartScraperGraph()+results = graph.scrape("https://example.com")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/smart_scraper/ollama/smart_scraper_lite_ollama.py b/examples/smart_scraper/ollama/smart_scraper_lite_ollama.pynew file mode 100644index 00000000..2cf6c402--- /dev/null+++ b/examples/smart_scraper/ollama/smart_scraper_lite_ollama.py@@ -0,0 +1,30 @@+"""+Basic example of scraping pipeline using SmartScraper++"""+import json+from scrapegraphai.graphs import SmartScraperLiteGraph+from scrapegraphai.utils import prettify_exec_info++graph_config = {+ "llm": {+ "model": "ollama/llama3.1",+ "temperature": 0,+ "format": "json",+ "base_url": "http://localhost:11434",+ },+ "verbose": True,+ "headless": False+}++smart_scraper_lite_graph = SmartScraperLiteGraph(+ prompt="Who is Marco Perini?",+ source="https://perinim.github.io/",+ config=graph_config+)++result = smart_scraper_lite_graph.run()+print(json.dumps(result, indent=4))++graph_exec_info = smart_scraper_lite_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/smart_scraper/ollama/smart_scraper_multi_concat_ollama.py b/examples/smart_scraper/ollama/smart_scraper_multi_concat_ollama.pynew file mode 100644index 00000000..665b5db4--- /dev/null+++ b/examples/smart_scraper/ollama/smart_scraper_multi_concat_ollama.py@@ -0,0 +1,42 @@+"""+Basic example of scraping pipeline using SmartScraper+"""++import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperMultiConcatGraph++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/llama3.1",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "verbose": True,+ "headless": False+}++# *******************************************************+# Create the SmartScraperMultiGraph instance and run it+# *******************************************************++multiple_search_graph = SmartScraperMultiConcatGraph(+ prompt="Who is Marco Perini?",+ source= [+ "https://perinim.github.io/",+ "https://perinim.github.io/cv/"+ ],+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/smart_scraper/ollama/smart_scraper_multi_lite_ollama.py b/examples/smart_scraper/ollama/smart_scraper_multi_lite_ollama.pynew file mode 100644index 00000000..f09c4cb4--- /dev/null+++ b/examples/smart_scraper/ollama/smart_scraper_multi_lite_ollama.py@@ -0,0 +1,45 @@+"""+Basic example of scraping pipeline using SmartScraper+"""+import json+from scrapegraphai.graphs import SmartScraperMultiLiteGraph+from scrapegraphai.utils import prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/llama3.1",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "verbose": True,+ "headless": False+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_multi_lite_graph = SmartScraperMultiLiteGraph(+ prompt="Who is Marco Perini?",+ source= [+ "https://perinim.github.io/",+ "https://perinim.github.io/cv/"+ ],+ config=graph_config+)++result = smart_scraper_multi_lite_graph.run()+print(json.dumps(result, indent=4))++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = smart_scraper_multi_lite_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))+diff --git a/examples/smart_scraper/ollama/smart_scraper_multi_ollama.py b/examples/smart_scraper/ollama/smart_scraper_multi_ollama.pynew file mode 100644index 00000000..c9d49793--- /dev/null+++ b/examples/smart_scraper/ollama/smart_scraper_multi_ollama.py@@ -0,0 +1,39 @@+"""+Basic example of scraping pipeline using SmartScraper+"""++import json+from scrapegraphai.graphs import SmartScraperMultiGraph++# ************************************************+# Define the configuration for the graph+# ************************************************+graph_config = {+ "llm": {+ "model": "ollama/llama3.1",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },++ "verbose": True,+ "headless": False+}+++# *******************************************************+# Create the SmartScraperMultiGraph instance and run it+# *******************************************************++multiple_search_graph = SmartScraperMultiGraph(+ prompt="Who is Marco Perini?",+ source= [+ "https://perinim.github.io/",+ "https://perinim.github.io/cv/"+ ],+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/local_models/smart_scraper_ollama.py b/examples/smart_scraper/ollama/smart_scraper_ollama.pysimilarity index 100%rename from examples/local_models/smart_scraper_ollama.pyrename to examples/smart_scraper/ollama/smart_scraper_ollama.pydiff --git a/examples/smart_scraper/ollama/smart_scraper_schema_ollama.py b/examples/smart_scraper/ollama/smart_scraper_schema_ollama.pynew file mode 100644index 00000000..5a5b3cea--- /dev/null+++ b/examples/smart_scraper/ollama/smart_scraper_schema_ollama.py@@ -0,0 +1,43 @@+"""+Basic example of scraping pipeline using SmartScraper with schema+"""+import json+from typing import List+from pydantic import BaseModel, Field+from scrapegraphai.graphs import SmartScraperGraph+from scrapegraphai.utils import prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************+class Project(BaseModel):+ title: str = Field(description="The title of the project")+ description: str = Field(description="The description of the project")++class Projects(BaseModel):+ projects: List[Project]++graph_config = {+ "llm": {+ "model": "ollama/llama3.1",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "verbose": True,+ "headless": False+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_graph = SmartScraperGraph(+ prompt="List me all the projects with their description",+ source="https://perinim.github.io/projects/",+ schema=Projects,+ config=graph_config+)++result = smart_scraper_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/smart_scraper/openai/smart_scraper_lite_openai.py b/examples/smart_scraper/openai/smart_scraper_lite_openai.pynew file mode 100644index 00000000..5de725bb--- /dev/null+++ b/examples/smart_scraper/openai/smart_scraper_lite_openai.py@@ -0,0 +1,32 @@+"""+Basic example of scraping pipeline using SmartScraper+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperLiteGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++graph_config = {+ "llm": {+ "api_key": os.getenv("OPENAI_API_KEY"),+ "model": "openai/gpt-4o",+ },+ "verbose": True,+ "headless": False,+}++smart_scraper_lite_graph = SmartScraperLiteGraph(+ prompt="Who is Marco Perini?",+ source="https://perinim.github.io/",+ config=graph_config+)++result = smart_scraper_lite_graph.run()+print(json.dumps(result, indent=4))++graph_exec_info = smart_scraper_lite_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))+diff --git a/examples/smart_scraper/openai/smart_scraper_multi_concat_openai.py b/examples/smart_scraper/openai/smart_scraper_multi_concat_openai.pynew file mode 100644index 00000000..650971f1--- /dev/null+++ b/examples/smart_scraper/openai/smart_scraper_multi_concat_openai.py@@ -0,0 +1,40 @@+"""+Basic example of scraping pipeline using SmartScraper+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperMultiConcatGraph++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************+openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ },+ "verbose": True,+ "headless": False,+}++# *******************************************************+# Create the SmartScraperMultiGraph instance and run it+# *******************************************************++multiple_search_graph = SmartScraperMultiConcatGraph(+ prompt="Who is Marco Perini?",+ source= [+ "https://perinim.github.io/",+ "https://perinim.github.io/cv/"+ ],+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/smart_scraper/openai/smart_scraper_multi_lite_openai.py b/examples/smart_scraper/openai/smart_scraper_multi_lite_openai.pynew file mode 100644index 00000000..69eeafc7--- /dev/null+++ b/examples/smart_scraper/openai/smart_scraper_multi_lite_openai.py@@ -0,0 +1,47 @@+"""+Basic example of scraping pipeline using SmartScraper+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperMultiLiteGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************+++graph_config = {+ "llm": {+ "api_key": os.getenv("OPENAI_API_KEY"),+ "model": "openai/gpt-4o",+ },+ "verbose": True,+ "headless": False,+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_multi_lite_graph = SmartScraperMultiLiteGraph(+ prompt="Who is Marco Perini?",+ source= [+ "https://perinim.github.io/",+ "https://perinim.github.io/cv/"+ ],+ config=graph_config+)++result = smart_scraper_multi_lite_graph.run()+print(json.dumps(result, indent=4))++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = smart_scraper_multi_lite_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/smart_scraper/openai/smart_scraper_multi_openai.py b/examples/smart_scraper/openai/smart_scraper_multi_openai.pynew file mode 100644index 00000000..ba889c96--- /dev/null+++ b/examples/smart_scraper/openai/smart_scraper_multi_openai.py@@ -0,0 +1,41 @@+"""+Basic example of scraping pipeline using SmartScraper+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperMultiGraph++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o",+ },+ "verbose": True,+ "headless": False,+}++# *******************************************************+# Create the SmartScraperMultiGraph instance and run it+# *******************************************************++multiple_search_graph = SmartScraperMultiGraph(+ prompt="Who is Marco Perini?",+ source= [+ "https://perinim.github.io/",+ "https://perinim.github.io/cv/"+ ],+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/openai/smart_scraper_openai.py b/examples/smart_scraper/openai/smart_scraper_openai.pysimilarity index 100%rename from examples/openai/smart_scraper_openai.pyrename to examples/smart_scraper/openai/smart_scraper_openai.pydiff --git a/examples/smart_scraper/openai/smart_scraper_schema_openai.py b/examples/smart_scraper/openai/smart_scraper_schema_openai.pynew file mode 100644index 00000000..32e8891a--- /dev/null+++ b/examples/smart_scraper/openai/smart_scraper_schema_openai.py@@ -0,0 +1,50 @@+"""+Basic example of scraping pipeline using SmartScraper with schema+"""+import os+from typing import List+from dotenv import load_dotenv+from pydantic import BaseModel, Field+from scrapegraphai.graphs import SmartScraperGraph++load_dotenv()++# ************************************************+# Define the output schema for the graph+# ************************************************++class Project(BaseModel):+ title: str = Field(description="The title of the project")+ description: str = Field(description="The description of the project")++class Projects(BaseModel):+ projects: List[Project]++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "openai/gpt-4o-mini",+ },+ "verbose": True,+ "headless": False,+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_graph = SmartScraperGraph(+ prompt="List me all the projects with their description",+ source="https://perinim.github.io/projects/",+ schema=Projects,+ config=graph_config+)++result = smart_scraper_graph.run()+print(result)diff --git a/examples/speech_graph/.env.example b/examples/speech_graph/.env.examplenew file mode 100644index 00000000..93aa505d--- /dev/null+++ b/examples/speech_graph/.env.example@@ -0,0 +1,14 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Whisper API Configuration (Optional)+WHISPER_API_KEY=your-whisper-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# Speech Settings+AUDIO_FORMAT=mp3+SAMPLE_RATE=16000\ No newline at end of filediff --git a/examples/speech_graph/README.md b/examples/speech_graph/README.mdnew file mode 100644index 00000000..35be155f--- /dev/null+++ b/examples/speech_graph/README.md@@ -0,0 +1,31 @@+# Speech Graph Example++This example demonstrates how to use Scrapegraph-ai for speech processing and analysis.++## Features++- Speech-to-text conversion+- Audio processing+- Text analysis+- Sentiment analysis++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import SpeechGraph++graph = SpeechGraph()+text = graph.process("audio_file.mp3")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key+- `WHISPER_API_KEY`: Your Whisper API key (optional)\ No newline at end of filediff --git a/examples/openai/speech_graph_openai.py b/examples/speech_graph/speech_graph_openai.pysimilarity index 100%rename from examples/openai/speech_graph_openai.pyrename to examples/speech_graph/speech_graph_openai.pydiff --git a/examples/xml_scraper_graph/.env.example b/examples/xml_scraper_graph/.env.examplenew file mode 100644index 00000000..9f0d484b--- /dev/null+++ b/examples/xml_scraper_graph/.env.example@@ -0,0 +1,11 @@+# OpenAI API Configuration+OPENAI_API_KEY=your-openai-api-key-here++# Optional Configurations+MAX_TOKENS=4000+MODEL_NAME=gpt-4-1106-preview+TEMPERATURE=0.7++# XML Scraper Settings+XPATH_TIMEOUT=30+VALIDATE_XML=true\ No newline at end of filediff --git a/examples/xml_scraper_graph/README.md b/examples/xml_scraper_graph/README.mdnew file mode 100644index 00000000..ed7eaf30--- /dev/null+++ b/examples/xml_scraper_graph/README.md@@ -0,0 +1,30 @@+# XML Scraper Graph Example++This example demonstrates how to use Scrapegraph-ai to extract and process XML data from web sources.++## Features++- XML data extraction+- XPath querying+- Data transformation+- Schema validation++## Setup++1. Install required dependencies+2. Copy `.env.example` to `.env`+3. Configure your API keys in the `.env` file++## Usage++```python+from scrapegraphai.graphs import XmlScraperGraph++graph = XmlScraperGraph()+xml_data = graph.scrape("https://example.com/feed.xml")+```++## Environment Variables++Required environment variables:+- `OPENAI_API_KEY`: Your OpenAI API key\ No newline at end of filediff --git a/examples/xml_scraper_graph/ollama/inputs/books.xml b/examples/xml_scraper_graph/ollama/inputs/books.xmlnew file mode 100644index 00000000..e3d1fe87--- /dev/null+++ b/examples/xml_scraper_graph/ollama/inputs/books.xml@@ -0,0 +1,120 @@+<?xml version="1.0"?>+<catalog>+ <book id="bk101">+ <author>Gambardella, Matthew</author>+ <title>XML Developer's Guide</title>+ <genre>Computer</genre>+ <price>44.95</price>+ <publish_date>2000-10-01</publish_date>+ <description>An in-depth look at creating applications+ with XML.</description>+ </book>+ <book id="bk102">+ <author>Ralls, Kim</author>+ <title>Midnight Rain</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-12-16</publish_date>+ <description>A former architect battles corporate zombies,+ an evil sorceress, and her own childhood to become queen+ of the world.</description>+ </book>+ <book id="bk103">+ <author>Corets, Eva</author>+ <title>Maeve Ascendant</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-11-17</publish_date>+ <description>After the collapse of a nanotechnology+ society in England, the young survivors lay the+ foundation for a new society.</description>+ </book>+ <book id="bk104">+ <author>Corets, Eva</author>+ <title>Oberon's Legacy</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-03-10</publish_date>+ <description>In post-apocalypse England, the mysterious+ agent known only as Oberon helps to create a new life+ for the inhabitants of London. Sequel to Maeve+ Ascendant.</description>+ </book>+ <book id="bk105">+ <author>Corets, Eva</author>+ <title>The Sundered Grail</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-09-10</publish_date>+ <description>The two daughters of Maeve, half-sisters,+ battle one another for control of England. Sequel to+ Oberon's Legacy.</description>+ </book>+ <book id="bk106">+ <author>Randall, Cynthia</author>+ <title>Lover Birds</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-09-02</publish_date>+ <description>When Carla meets Paul at an ornithology+ conference, tempers fly as feathers get ruffled.</description>+ </book>+ <book id="bk107">+ <author>Thurman, Paula</author>+ <title>Splish Splash</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>A deep sea diver finds true love twenty+ thousand leagues beneath the sea.</description>+ </book>+ <book id="bk108">+ <author>Knorr, Stefan</author>+ <title>Creepy Crawlies</title>+ <genre>Horror</genre>+ <price>4.95</price>+ <publish_date>2000-12-06</publish_date>+ <description>An anthology of horror stories about roaches,+ centipedes, scorpions and other insects.</description>+ </book>+ <book id="bk109">+ <author>Kress, Peter</author>+ <title>Paradox Lost</title>+ <genre>Science Fiction</genre>+ <price>6.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>After an inadvertant trip through a Heisenberg+ Uncertainty Device, James Salway discovers the problems+ of being quantum.</description>+ </book>+ <book id="bk110">+ <author>O'Brien, Tim</author>+ <title>Microsoft .NET: The Programming Bible</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-09</publish_date>+ <description>Microsoft's .NET initiative is explored in+ detail in this deep programmer's reference.</description>+ </book>+ <book id="bk111">+ <author>O'Brien, Tim</author>+ <title>MSXML3: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-01</publish_date>+ <description>The Microsoft MSXML3 parser is covered in+ detail, with attention to XML DOM interfaces, XSLT processing,+ SAX and more.</description>+ </book>+ <book id="bk112">+ <author>Galos, Mike</author>+ <title>Visual Studio 7: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>49.95</price>+ <publish_date>2001-04-16</publish_date>+ <description>Microsoft Visual Studio 7 is explored in depth,+ looking at how Visual Basic, Visual C++, C#, and ASP+ are+ integrated into a comprehensive development+ environment.</description>+ </book>+</catalog>\ No newline at end of filediff --git a/examples/xml_scraper_graph/ollama/xml_scraper_graph_multi_ollama.py b/examples/xml_scraper_graph/ollama/xml_scraper_graph_multi_ollama.pynew file mode 100644index 00000000..0494ff2c--- /dev/null+++ b/examples/xml_scraper_graph/ollama/xml_scraper_graph_multi_ollama.py@@ -0,0 +1,58 @@+"""+Basic example of scraping pipeline using XMLScraperMultiGraph from XML documents+"""++import os+from scrapegraphai.graphs import XMLScraperMultiGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Read the XML file+# ************************************************++FILE_NAME = "inputs/books.xml"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/llama3",+ "temperature": 0,+ "format": "json", # Ollama needs the format to be specified explicitly+ # "model_tokens": 2000, # set context length arbitrarily+ "base_url": "http://localhost:11434",+ },++ "verbose": True,+}++# ************************************************+# Create the XMLScraperMultiGraph instance and run it+# ************************************************++xml_scraper_graph = XMLScraperMultiGraph(+ prompt="List me all the authors, title and genres of the books",+ source=[text, text], # Pass the content of the file, not the file object+ config=graph_config+)++result = xml_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = xml_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/xml_scraper_graph/ollama/xml_scraper_ollama.py b/examples/xml_scraper_graph/ollama/xml_scraper_ollama.pynew file mode 100644index 00000000..50c4f8e7--- /dev/null+++ b/examples/xml_scraper_graph/ollama/xml_scraper_ollama.py@@ -0,0 +1,58 @@+"""+Basic example of scraping pipeline using XMLScraperGraph from XML documents+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import XMLScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Read the XML file+# ************************************************++FILE_NAME = "inputs/books.xml"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ollama/llama3",+ "temperature": 0,+ # "model_tokens": 2000, # set context length arbitrarily+ "base_url": "http://localhost:11434",+ },+ "verbose": True,+}++# ************************************************+# Create the XMLScraperGraph instance and run it+# ************************************************++xml_scraper_graph = XMLScraperGraph(+ prompt="List me all the authors, title and genres of the books",+ source=text, # Pass the content of the file, not the file object+ config=graph_config+)++result = xml_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = xml_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/xml_scraper_graph/openai/inputs/books.xml b/examples/xml_scraper_graph/openai/inputs/books.xmlnew file mode 100644index 00000000..e3d1fe87--- /dev/null+++ b/examples/xml_scraper_graph/openai/inputs/books.xml@@ -0,0 +1,120 @@+<?xml version="1.0"?>+<catalog>+ <book id="bk101">+ <author>Gambardella, Matthew</author>+ <title>XML Developer's Guide</title>+ <genre>Computer</genre>+ <price>44.95</price>+ <publish_date>2000-10-01</publish_date>+ <description>An in-depth look at creating applications+ with XML.</description>+ </book>+ <book id="bk102">+ <author>Ralls, Kim</author>+ <title>Midnight Rain</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-12-16</publish_date>+ <description>A former architect battles corporate zombies,+ an evil sorceress, and her own childhood to become queen+ of the world.</description>+ </book>+ <book id="bk103">+ <author>Corets, Eva</author>+ <title>Maeve Ascendant</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-11-17</publish_date>+ <description>After the collapse of a nanotechnology+ society in England, the young survivors lay the+ foundation for a new society.</description>+ </book>+ <book id="bk104">+ <author>Corets, Eva</author>+ <title>Oberon's Legacy</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-03-10</publish_date>+ <description>In post-apocalypse England, the mysterious+ agent known only as Oberon helps to create a new life+ for the inhabitants of London. Sequel to Maeve+ Ascendant.</description>+ </book>+ <book id="bk105">+ <author>Corets, Eva</author>+ <title>The Sundered Grail</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-09-10</publish_date>+ <description>The two daughters of Maeve, half-sisters,+ battle one another for control of England. Sequel to+ Oberon's Legacy.</description>+ </book>+ <book id="bk106">+ <author>Randall, Cynthia</author>+ <title>Lover Birds</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-09-02</publish_date>+ <description>When Carla meets Paul at an ornithology+ conference, tempers fly as feathers get ruffled.</description>+ </book>+ <book id="bk107">+ <author>Thurman, Paula</author>+ <title>Splish Splash</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>A deep sea diver finds true love twenty+ thousand leagues beneath the sea.</description>+ </book>+ <book id="bk108">+ <author>Knorr, Stefan</author>+ <title>Creepy Crawlies</title>+ <genre>Horror</genre>+ <price>4.95</price>+ <publish_date>2000-12-06</publish_date>+ <description>An anthology of horror stories about roaches,+ centipedes, scorpions and other insects.</description>+ </book>+ <book id="bk109">+ <author>Kress, Peter</author>+ <title>Paradox Lost</title>+ <genre>Science Fiction</genre>+ <price>6.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>After an inadvertant trip through a Heisenberg+ Uncertainty Device, James Salway discovers the problems+ of being quantum.</description>+ </book>+ <book id="bk110">+ <author>O'Brien, Tim</author>+ <title>Microsoft .NET: The Programming Bible</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-09</publish_date>+ <description>Microsoft's .NET initiative is explored in+ detail in this deep programmer's reference.</description>+ </book>+ <book id="bk111">+ <author>O'Brien, Tim</author>+ <title>MSXML3: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-01</publish_date>+ <description>The Microsoft MSXML3 parser is covered in+ detail, with attention to XML DOM interfaces, XSLT processing,+ SAX and more.</description>+ </book>+ <book id="bk112">+ <author>Galos, Mike</author>+ <title>Visual Studio 7: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>49.95</price>+ <publish_date>2001-04-16</publish_date>+ <description>Microsoft Visual Studio 7 is explored in depth,+ looking at how Visual Basic, Visual C++, C#, and ASP+ are+ integrated into a comprehensive development+ environment.</description>+ </book>+</catalog>\ No newline at end of filediff --git a/examples/xml_scraper_graph/openai/xml_scraper_graph_multi_openai.py b/examples/xml_scraper_graph/openai/xml_scraper_graph_multi_openai.pynew file mode 100644index 00000000..3604489b--- /dev/null+++ b/examples/xml_scraper_graph/openai/xml_scraper_graph_multi_openai.py@@ -0,0 +1,58 @@+"""+Basic example of scraping pipeline using XMLScraperMultiGraph from XML documents+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import XMLScraperMultiGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++load_dotenv()++# ************************************************+# Read the XML file+# ************************************************++FILE_NAME = "inputs/books.xml"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key":openai_key,+ "model": "openai/gpt-4o",+ },+ "verbose": True,+ "headless": False,+}+# ************************************************+# Create the XMLScraperMultiGraph instance and run it+# ************************************************++xml_scraper_graph = XMLScraperMultiGraph(+ prompt="List me all the authors, title and genres of the books",+ source=[text, text], # Pass the content of the file, not the file object+ config=graph_config+)++result = xml_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = xml_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/openai/xml_scraper_openai.py b/examples/xml_scraper_graph/openai/xml_scraper_openai.pysimilarity index 100%rename from examples/openai/xml_scraper_openai.pyrename to examples/xml_scraper_graph/openai/xml_scraper_openai.py