mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-06-23 21:00:30 +08:00
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""
|
|
Basic example of scraping pipeline using ScriptCreatorGraph
|
|
"""
|
|
|
|
import os
|
|
from dotenv import load_dotenv
|
|
from scrapegraphai.graphs import ScriptCreatorGraph
|
|
from langchain_openai import AzureChatOpenAI
|
|
from langchain_openai import AzureOpenAIEmbeddings
|
|
from scrapegraphai.utils import prettify_exec_info
|
|
|
|
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}
|
|
}
|
|
|
|
# ************************************************
|
|
# 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
|
|
)
|
|
|
|
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))
|
|
|