Skip to content

Python scraper based on AI

Create browser_base.py

Marco Vinciguerrafb87d01ced72
diff --git a/examples/extras/browser_base.py b/examples/extras/browser_base.py
new file mode 100644
index 00000000..465c80ba
--- /dev/null
+++ b/examples/extras/browser_base.py
@@ -0,0 +1,47 @@
+"""
+Basic example of scraping pipeline using SmartScraper
+"""
+
+import os, json
+from scrapegraphai.graphs import SmartScraperGraph
+from scrapegraphai.utils import prettify_exec_info
+from dotenv import load_dotenv
+load_dotenv()
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+
+graph_config = {
+ "llm": {
+ "api_key": os.getenv("OPENAI_API_KEY"),
+ "model": "gpt-3.5-turbo",
+ },
+ "browser_base": {
+ "api_key": os.getenv("BROWSER_BASE_API_KEY"),
+ "project_id": os.getenv("BROWSER_BASE_API_KEY"),
+ },
+ "verbose": True,
+ "headless": False,
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+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 = 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))