mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-06-25 21:11:11 +08:00
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"""
|
|
Basic example of scraping pipeline using SmartScraper
|
|
"""
|
|
|
|
import os
|
|
from dotenv import load_dotenv
|
|
from scrapegraphai.graphs import DeepScraperGraph
|
|
from scrapegraphai.utils import prettify_exec_info
|
|
|
|
load_dotenv()
|
|
|
|
|
|
# ************************************************
|
|
# Define the configuration for the graph
|
|
# ************************************************
|
|
|
|
openai_key = os.getenv("OPENAI_APIKEY")
|
|
|
|
graph_config = {
|
|
"llm": {
|
|
"api_key": openai_key,
|
|
"model": "gpt-4",
|
|
},
|
|
"verbose": True,
|
|
}
|
|
|
|
# ************************************************
|
|
# Create the SmartScraperGraph instance and run it
|
|
# ************************************************
|
|
|
|
deep_scraper_graph = DeepScraperGraph(
|
|
prompt="List me all the job titles and detailed job description.",
|
|
# also accepts a string with the already downloaded HTML code
|
|
source="https://www.google.com/about/careers/applications/jobs/results/?location=Bangalore%20India",
|
|
config=graph_config
|
|
)
|
|
|
|
result = deep_scraper_graph.run()
|
|
print(result)
|
|
|
|
# ************************************************
|
|
# Get graph execution info
|
|
# ************************************************
|
|
|
|
graph_exec_info = deep_scraper_graph.get_execution_info()
|
|
print(deep_scraper_graph.get_state("relevant_links"))
|
|
print(prettify_exec_info(graph_exec_info)) |