Skip to content

Commit dc9d63c

Browse files
committed
add async schema
1 parent acf93c0 commit dc9d63c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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())

0 commit comments

Comments
 (0)