Skip to content

Commit

Permalink
Merge branch 'api-integration' into pre/beta
Browse files Browse the repository at this point in the history
  • Loading branch information
VinciGit00 committed Dec 2, 2024
2 parents 58ca0f5 + 209b445 commit 1ff7f88
Show file tree
Hide file tree
Showing 5 changed files with 1,024 additions and 1 deletion.
44 changes: 44 additions & 0 deletions examples/scrapegraph-api/smart_scraper_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Basic example of scraping pipeline using SmartScraper
"""
import os
import json
from dotenv import load_dotenv
from scrapegraphai.graphs import SmartScraperGraph
from scrapegraphai.utils import prettify_exec_info

load_dotenv()

# ************************************************
# Define the configuration for the graph
# ************************************************


graph_config = {
"llm": {
"model": "scrapegraphai/smart-scraper",
"api_key": os.getenv("SCRAPEGRAPH_API_KEY")
},
"verbose": True,
"headless": False,
}

# ************************************************
# Create the SmartScraperGraph instance and run it
# ************************************************

smart_scraper_graph = SmartScraperGraph(
prompt="Extract me all the articles",
source="https://www.wired.com",
config=graph_config
)

result = smart_scraper_graph.run()
print(json.dumps(result, indent=4))

# ************************************************
# Get graph execution info
# ************************************************

graph_exec_info = smart_scraper_graph.get_execution_info()
print(prettify_exec_info(graph_exec_info))
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ dependencies = [
"transformers>=4.44.2",
"googlesearch-python>=1.2.5",
"simpleeval>=1.0.0",
"async_timeout>=4.0.3"
"async_timeout>=4.0.3",
"scrapegraph-py>=0.0.4"
]

license = "MIT"
Expand Down
Loading

0 comments on commit 1ff7f88

Please sign in to comment.