|
| 1 | +""" |
| 2 | +Basic example of scraping pipeline using SmartScraper with a custom rate limit |
| 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 | + |
| 11 | +# required environment variable in .env |
| 12 | +# AZURE_OPENAI_ENDPOINT |
| 13 | +# AZURE_OPENAI_CHAT_DEPLOYMENT_NAME |
| 14 | +# MODEL_NAME |
| 15 | +# AZURE_OPENAI_API_KEY |
| 16 | +# OPENAI_API_TYPE |
| 17 | +# AZURE_OPENAI_API_VERSION |
| 18 | +# AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME |
| 19 | +load_dotenv() |
| 20 | + |
| 21 | + |
| 22 | +# ************************************************ |
| 23 | +# Initialize the model instances |
| 24 | +# ************************************************ |
| 25 | + |
| 26 | +graph_config = { |
| 27 | + "llm": { |
| 28 | + "api_key": os.environ["AZURE_OPENAI_KEY"], |
| 29 | + "model": "azure_openai/gpt-3.5-turbo", |
| 30 | + "rate_limit": { |
| 31 | + "requests_per_second": 1 |
| 32 | + }, |
| 33 | + }, |
| 34 | + "verbose": True, |
| 35 | + "headless": False |
| 36 | +} |
| 37 | + |
| 38 | +smart_scraper_graph = SmartScraperGraph( |
| 39 | + prompt="""List me all the events, with the following fields: company_name, event_name, event_start_date, event_start_time, |
| 40 | + event_end_date, event_end_time, location, event_mode, event_category, |
| 41 | + third_party_redirect, no_of_days, |
| 42 | + time_in_hours, hosted_or_attending, refreshments_type, |
| 43 | + registration_available, registration_link""", |
| 44 | + # also accepts a string with the already downloaded HTML code |
| 45 | + source="https://www.hmhco.com/event", |
| 46 | + config=graph_config |
| 47 | +) |
| 48 | + |
| 49 | +result = smart_scraper_graph.run() |
| 50 | +print(result) |
| 51 | + |
| 52 | +# ************************************************ |
| 53 | +# Get graph execution info |
| 54 | +# ************************************************ |
| 55 | + |
| 56 | +graph_exec_info = smart_scraper_graph.get_execution_info() |
| 57 | +print(prettify_exec_info(graph_exec_info)) |
0 commit comments