|
| 1 | +""" |
| 2 | +Basic example of scraping pipeline using SmartScraper |
| 3 | +""" |
| 4 | +import os |
| 5 | +import json |
| 6 | +from dotenv import load_dotenv |
| 7 | +from scrapegraphai.graphs import SmartScraperMultiLiteGraph |
| 8 | +from scrapegraphai.utils import prettify_exec_info |
| 9 | + |
| 10 | +load_dotenv() |
| 11 | + |
| 12 | +# ************************************************ |
| 13 | +# Define the configuration for the graph |
| 14 | +# ************************************************ |
| 15 | + |
| 16 | + |
| 17 | +graph_config = { |
| 18 | + "llm": { |
| 19 | + "api_key": os.getenv("OPENAI_API_KEY"), |
| 20 | + "model": "openai/gpt-4o", |
| 21 | + }, |
| 22 | + "verbose": True, |
| 23 | + "headless": False, |
| 24 | +} |
| 25 | + |
| 26 | +# ************************************************ |
| 27 | +# Create the SmartScraperGraph instance and run it |
| 28 | +# ************************************************ |
| 29 | + |
| 30 | +smart_scraper_multi_lite_graph = SmartScraperMultiLiteGraph( |
| 31 | + prompt="Who is Marco Perini?", |
| 32 | + source= [ |
| 33 | + "https://perinim.github.io/", |
| 34 | + "https://perinim.github.io/cv/" |
| 35 | + ], |
| 36 | + config=graph_config |
| 37 | +) |
| 38 | + |
| 39 | +result = smart_scraper_multi_lite_graph.run() |
| 40 | +print(json.dumps(result, indent=4)) |
| 41 | + |
| 42 | +# ************************************************ |
| 43 | +# Get graph execution info |
| 44 | +# ************************************************ |
| 45 | + |
| 46 | +graph_exec_info = smart_scraper_multi_lite_graph.get_execution_info() |
| 47 | +print(prettify_exec_info(graph_exec_info)) |
0 commit comments