Learn how to extract article information from Wired.com using ScrapeGraphAI’s SmartScraper. This example demonstrates how to gather article details, categories, and author information.
from pydantic import BaseModel, Fieldfrom typing import Listfrom scrapegraph_py import Client# Schema for a single news itemclass NewsItemSchema(BaseModel): category: str = Field(description="Category of the news (e.g., 'Health', 'Environment')") title: str = Field(description="Title of the news article") link: str = Field(description="URL to the news article") author: str = Field(description="Author of the news article")# Schema that contains a list of news itemsclass ListNewsSchema(BaseModel): news: List[NewsItemSchema] = Field(description="List of news articles with their details")client = Client(api_key="your-api-key")response = client.smartscraper( website_url="https://www.wired.com/", user_prompt="Extract latest news articles", output_schema=ListNewsSchema)