Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
add examples
Marco Vinciguerrac14fb88fca06
diff --git a/examples/anthropic/script_multi_generator_haiku.py b/examples/anthropic/script_multi_generator_haiku.pynew file mode 100644index 00000000..f7c69010--- /dev/null+++ b/examples/anthropic/script_multi_generator_haiku.py@@ -0,0 +1,53 @@+"""+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": {+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },+ "library": "beautifulsoup"+}++# ************************************************+# 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/anthropic/smart_scraper_multi_haiku.py b/examples/anthropic/smart_scraper_multi_haiku.pyindex 61b4bbe0..eb2001d4 100644--- a/examples/anthropic/smart_scraper_multi_haiku.py+++ b/examples/anthropic/smart_scraper_multi_haiku.py@@ -12,31 +12,14 @@ load_dotenv()# Define the configuration for the graph# ************************************************-openai_key = os.getenv("OPENAI_APIKEY")--"""-Basic example of scraping pipeline using SmartScraper-"""--import os, 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": "gpt-4o",- },- "verbose": True,- "headless": False,+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },}# *******************************************************diff --git a/examples/azure/script_generator_azure.py b/examples/azure/script_generator_azure.pyindex 0fe29c6d..17135f07 100644--- a/examples/azure/script_generator_azure.py+++ b/examples/azure/script_generator_azure.py@@ -25,7 +25,8 @@ embedder_model_instance = AzureOpenAIEmbeddings()graph_config = {"llm": {"model_instance": llm_model_instance},- "embeddings": {"model_instance": embedder_model_instance}+ "embeddings": {"model_instance": embedder_model_instance},+ "library": "beautifulsoup"}# ************************************************diff --git a/examples/azure/script_multi_generator_azure.py b/examples/azure/script_multi_generator_azure.pynew file mode 100644index 00000000..389eac03--- /dev/null+++ b/examples/azure/script_multi_generator_azure.py@@ -0,0 +1,61 @@+"""+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+from langchain_openai import AzureChatOpenAI+from langchain_openai import AzureOpenAIEmbeddings++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************+llm_model_instance = AzureChatOpenAI(+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+ azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"]+)++embedder_model_instance = AzureOpenAIEmbeddings(+ azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+)+graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance},+ "library": "beautifulsoup"+}+++# ************************************************+# 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/bedrock/script_multi_generator_bedrock.py b/examples/bedrock/script_multi_generator_bedrock.pynew file mode 100644index 00000000..2f892546--- /dev/null+++ b/examples/bedrock/script_multi_generator_bedrock.py@@ -0,0 +1,52 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""++from scrapegraphai.graphs import ScriptCreatorMultiGraph+from scrapegraphai.utils import prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "client": "client_name",+ "model": "bedrock/anthropic.claude-3-sonnet-20240229-v1:0",+ "temperature": 0.0+ },+ "embeddings": {+ "model": "bedrock/cohere.embed-multilingual-v3"+ },+ "library": "beautifulsoup"+}++# ************************************************+# 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/deepseek/script_multi_generator_deepseek.py b/examples/deepseek/script_multi_generator_deepseek.pynew file mode 100644index 00000000..41e363b5--- /dev/null+++ b/examples/deepseek/script_multi_generator_deepseek.py@@ -0,0 +1,60 @@+"""+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+# ************************************************++deepseek_key = os.getenv("DEEPSEEK_APIKEY")++graph_config = {+ "llm": {+ "model": "deepseek-chat",+ "openai_api_key": deepseek_key,+ "openai_api_base": 'https://api.deepseek.com/v1',+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "library": "beautifulsoup"+}++# ************************************************+# 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/ernie/script_multi_generator_ernie.py b/examples/ernie/script_multi_generator_ernie.pynew file mode 100644index 00000000..73e9f5ab--- /dev/null+++ b/examples/ernie/script_multi_generator_ernie.py@@ -0,0 +1,54 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""++from scrapegraphai.graphs import ScriptCreatorMultiGraph+from scrapegraphai.utils import prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ernie-bot-turbo",+ "ernie_client_id": "<ernie_client_id>",+ "ernie_client_secret": "<ernie_client_secret>",+ "temperature": 0.1+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ "base_url": "http://localhost:11434"},+ "library": "beautifulsoup"+}++# ************************************************+# 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/gemini/script_multi_generator_gemini.py b/examples/gemini/script_multi_generator_gemini.pynew file mode 100644index 00000000..f4f7c26c--- /dev/null+++ b/examples/gemini/script_multi_generator_gemini.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+# ************************************************++gemini_key = os.getenv("GOOGLE_APIKEY")++graph_config = {+ "llm": {+ "api_key": gemini_key,+ "model": "gemini-pro",+ },+ "library": "beautifoulsoup"+}++# ************************************************+# 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/groq/script_multi_generator_groq.py b/examples/groq/script_multi_generator_groq.pynew file mode 100644index 00000000..1757a3de--- /dev/null+++ b/examples/groq/script_multi_generator_groq.py@@ -0,0 +1,60 @@+"""+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+# ************************************************++groq_key = os.getenv("GROQ_APIKEY")++graph_config = {+ "llm": {+ "model": "groq/gemma-7b-it",+ "api_key": groq_key,+ "temperature": 0+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "library": "beautifulsoup"+}++# ************************************************+# 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/huggingfacehub/script_multi_generator_huggingfacehub.py b/examples/huggingfacehub/script_multi_generator_huggingfacehub.pynew file mode 100644index 00000000..5afeff0d--- /dev/null+++ b/examples/huggingfacehub/script_multi_generator_huggingfacehub.py@@ -0,0 +1,67 @@+"""+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+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# 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/local_models/script_multi_generator_ollama.py b/examples/local_models/script_multi_generator_ollama.pynew file mode 100644index 00000000..dc34c910--- /dev/null+++ b/examples/local_models/script_multi_generator_ollama.py@@ -0,0 +1,60 @@+"""+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+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ "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/oneapi/script_multi_generator_oneapi.py b/examples/oneapi/script_multi_generator_oneapi.pynew file mode 100644index 00000000..b9c5bfef--- /dev/null+++ b/examples/oneapi/script_multi_generator_oneapi.py@@ -0,0 +1,49 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""++from scrapegraphai.graphs import ScriptCreatorMultiGraph+from scrapegraphai.utils import prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "api_key": "***************************",+ "model": "oneapi/qwen-turbo",+ "base_url": "http://127.0.0.1:3000/v1", # 设置 OneAPI URL+ },+ "library": "beautifulsoup"+}++# ************************************************+# 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))