Skip to content

Python scraper based on AI

Update script_generator_openai.py

Marco Vinciguerrad29f7471514a
diff --git a/examples/openai/script_generator_openai.py b/examples/openai/script_generator_openai.py
index e67ad52b..119f67e5 100644
--- a/examples/openai/script_generator_openai.py
+++ b/examples/openai/script_generator_openai.py
@@ -1,10 +1,11 @@
"""
-Basic example of scraping pipeline using ScriptCreatorGraph
+Basic example of scraping pipeline using SmartScraper
"""
import os
+import json
from dotenv import load_dotenv
-from scrapegraphai.graphs import ScriptCreatorGraph
+from scrapegraphai.graphs import SmartScraperGraph
from scrapegraphai.utils import prettify_exec_info
load_dotenv()
@@ -13,34 +14,32 @@ 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",
+ "api_key": os.getenv("OPENAI_API_KEY"),
+ "model": "gpt-4o",
},
- "library": "beautifulsoup"
+ "verbose": True,
+ "headless": False,
}
# ************************************************
-# Create the ScriptCreatorGraph instance and run it
+# Create the SmartScraperGraph 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",
+smart_scraper_graph = SmartScraperGraph(
+ prompt="List me what does the company do, the name and a contact email.",
+ source="https://scrapegraphai.com/",
config=graph_config
)
-result = script_creator_graph.run()
-print(result)
+result = smart_scraper_graph.run()
+print(json.dumps(result, indent=4))
# ************************************************
# Get graph execution info
# ************************************************
-graph_exec_info = script_creator_graph.get_execution_info()
+graph_exec_info = smart_scraper_graph.get_execution_info()
print(prettify_exec_info(graph_exec_info))
-