|
| 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 | +load_dotenv() |
| 10 | + |
| 11 | +# ************************************************ |
| 12 | +# Define the configuration for the graph |
| 13 | +# ************************************************ |
| 14 | + |
| 15 | +groq_key = os.getenv("GROQ_APIKEY") |
| 16 | + |
| 17 | +graph_config = { |
| 18 | + "llm": { |
| 19 | + "model": "groq/gemma-7b-it", |
| 20 | + "api_key": groq_key, |
| 21 | + "temperature": 0 |
| 22 | + }, |
| 23 | + "embeddings": { |
| 24 | + "model": "ollama/nomic-embed-text", |
| 25 | + "temperature": 0, |
| 26 | + "base_url": "http://localhost:11434", # set ollama URL arbitrarily |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +# ************************************************ |
| 31 | +# Create the SmartScraperGraph instance and run it |
| 32 | +# ************************************************ |
| 33 | + |
| 34 | +smart_scraper_graph = SmartScraperGraph( |
| 35 | + prompt="List me all the projects with their description and the author.", |
| 36 | + # also accepts a string with the already downloaded HTML code |
| 37 | + source="https://perinim.github.io/projects", |
| 38 | + config=graph_config |
| 39 | +) |
| 40 | + |
| 41 | +result = smart_scraper_graph.run() |
| 42 | +print(result) |
| 43 | + |
| 44 | +# ************************************************ |
| 45 | +# Get graph execution info |
| 46 | +# ************************************************ |
| 47 | + |
| 48 | +graph_exec_info = smart_scraper_graph.get_execution_info() |
| 49 | +print(prettify_exec_info(graph_exec_info)) |
0 commit comments