File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ import asyncio
2+ from pydantic import BaseModel , Field
3+ from scrapegraph_py import AsyncClient
4+
5+
6+ # Define a Pydantic model for the output schema
7+ class WebpageSchema (BaseModel ):
8+ title : str = Field (description = "The title of the webpage" )
9+ description : str = Field (description = "The description of the webpage" )
10+ summary : str = Field (description = "A brief summary of the webpage" )
11+
12+
13+ async def main ():
14+ # Initialize the async client
15+ sgai_client = AsyncClient (api_key = "your-api-key-here" )
16+
17+ # SmartScraper request with output schema
18+ response = await sgai_client .smartscraper (
19+ website_url = "https://example.com" ,
20+ user_prompt = "Extract webpage information" ,
21+ output_schema = WebpageSchema ,
22+ )
23+
24+ # Print the response
25+ print (f"Request ID: { response ['request_id' ]} " )
26+ print (f"Result: { response ['result' ]} " )
27+
28+ await sgai_client .close ()
29+
30+ if __name__ == "__main__" :
31+ asyncio .run (main ())
You can’t perform that action at this time.
0 commit comments