|
| 1 | +""" |
| 2 | +Basic example of scraping pipeline using SmartScraper |
| 3 | +""" |
| 4 | + |
| 5 | +import os, json |
| 6 | +from scrapegraphai.graphs import SmartScraperGraph |
| 7 | +from scrapegraphai.utils import prettify_exec_info |
| 8 | +from dotenv import load_dotenv |
| 9 | +load_dotenv() |
| 10 | + |
| 11 | +# ************************************************ |
| 12 | +# Define the configuration for the graph |
| 13 | +# ************************************************ |
| 14 | + |
| 15 | + |
| 16 | +graph_config = { |
| 17 | + "llm": { |
| 18 | + "api_key": os.getenv("OPENAI_API_KEY"), |
| 19 | + "model": "gpt-3.5-turbo", |
| 20 | + }, |
| 21 | + "browser_base": { |
| 22 | + "api_key": os.getenv("BROWSER_BASE_API_KEY"), |
| 23 | + "project_id": os.getenv("BROWSER_BASE_API_KEY"), |
| 24 | + }, |
| 25 | + "verbose": True, |
| 26 | + "headless": False, |
| 27 | +} |
| 28 | + |
| 29 | +# ************************************************ |
| 30 | +# Create the SmartScraperGraph instance and run it |
| 31 | +# ************************************************ |
| 32 | + |
| 33 | +smart_scraper_graph = SmartScraperGraph( |
| 34 | + prompt="List me what does the company do, the name and a contact email.", |
| 35 | + source="https://scrapegraphai.com/", |
| 36 | + config=graph_config |
| 37 | +) |
| 38 | + |
| 39 | +result = smart_scraper_graph.run() |
| 40 | +print(json.dumps(result, indent=4)) |
| 41 | + |
| 42 | +# ************************************************ |
| 43 | +# Get graph execution info |
| 44 | +# ************************************************ |
| 45 | + |
| 46 | +graph_exec_info = smart_scraper_graph.get_execution_info() |
| 47 | +print(prettify_exec_info(graph_exec_info)) |
0 commit comments