|
| 1 | +""" |
| 2 | +Basic example of scraping pipeline using SmartScraper |
| 3 | +""" |
| 4 | + |
| 5 | +import os |
| 6 | +from dotenv import load_dotenv |
| 7 | +from scrapegraphai.graphs import SmartScraperGraph |
| 8 | +from scrapegraphai.utils import prettify_exec_info |
| 9 | + |
| 10 | +load_dotenv() |
| 11 | + |
| 12 | + |
| 13 | +# ************************************************ |
| 14 | +# Define the configuration for the graph |
| 15 | +# ************************************************ |
| 16 | + |
| 17 | +deepseek_key = os.getenv("DEEPSEEK_APIKEY") |
| 18 | + |
| 19 | +graph_config = { |
| 20 | + "llm": { |
| 21 | + "model": "deepseek-chat", |
| 22 | + "openai_api_key": deepseek_key, |
| 23 | + "openai_api_base": 'https://api.deepseek.com/v1', |
| 24 | + }, |
| 25 | + "verbose": True, |
| 26 | +} |
| 27 | + |
| 28 | +# ************************************************ |
| 29 | +# Create the SmartScraperGraph instance and run it |
| 30 | +# ************************************************ |
| 31 | + |
| 32 | +smart_scraper_graph = SmartScraperGraph( |
| 33 | + prompt="List me all the projects with their description.", |
| 34 | + # also accepts a string with the already downloaded HTML code |
| 35 | + source="https://perinim.github.io/projects/", |
| 36 | + config=graph_config |
| 37 | +) |
| 38 | + |
| 39 | +result = smart_scraper_graph.run() |
| 40 | +print(result) |
| 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