Use this file to discover all available pages before exploring further.
Learn how to extract article information from Wired.com using ScrapeGraphAI’s Extract service. This example demonstrates how to gather article details, categories, and author information.
from pydantic import BaseModel, Fieldfrom typing import Listfrom scrapegraph_py import ScrapeGraphAI# 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")sgai = ScrapeGraphAI() # reads SGAI_API_KEY from envres = sgai.extract( "Extract latest news articles", url="https://www.wired.com/", schema=ListNewsSchema.model_json_schema(),)if res.status == "success": print(res.data.json_data)