Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.scrapegraphai.com/llms.txt

Use this file to discover all available pages before exploring further.

Learn how to extract property listings from Homes.com using ScrapeGraphAIโ€™s Extract service. This example demonstrates how to gather detailed property information, pricing, and agent details.

The Goal

Weโ€™ll extract the following property information:
FieldDescription
PriceProperty price in USD
BedroomsNumber of bedrooms
BathroomsNumber of bathrooms
Square FeetTotal square footage
AddressProperty address
CityProperty city
StateProperty state
ZIP CodeLocation ZIP code
TagsProperty features
AgentListing agent name
AgencyListing agency

Code Example

from pydantic import BaseModel, Field
from typing import List, Optional
from scrapegraph_py import ScrapeGraphAI

# Schema for a single house listing
class HouseSchema(BaseModel):
    price: int = Field(description="Price of the house in USD")
    bedrooms: int = Field(description="Number of bedrooms")
    bathrooms: int = Field(description="Number of bathrooms")
    square_feet: int = Field(description="Total square footage of the house")
    address: str = Field(description="Address of the house")
    city: str = Field(description="City where the house is located")
    state: str = Field(description="State where the house is located")
    zip_code: str = Field(description="ZIP code of the house location")
    tags: List[str] = Field(description="Tags like 'New construction' or 'Large garage'")
    agent_name: str = Field(description="Name of the listing agent")
    agency: str = Field(description="Agency listing the house")

# Schema containing a list of house listings
class HouseListingsSchema(BaseModel):
    houses: List[HouseSchema] = Field(description="List of house listings on Homes.com or similar platforms")

sgai = ScrapeGraphAI()  # reads SGAI_API_KEY from env

res = sgai.extract(
    "Extract property listings information",
    url="https://www.homes.com/san-francisco-ca/?bb=nzpwspy0mS749snkvsb",
    schema=HouseListingsSchema.model_json_schema(),
)

if res.status == "success":
    print(res.data.json_data)

Example Output

{
    "houses": [
        {
            "price": 750000,
            "bedrooms": 4,
            "bathrooms": 3,
            "square_feet": 2500,
            "address": "123 Main Street",
            "city": "San Francisco",
            "state": "CA",
            "zip_code": "94105",
            "tags": ["New Construction", "Smart Home", "Mountain View"],
            "agent_name": "Jane Smith",
            "agency": "Bay Area Realty"
        },
        {
            "price": 525000,
            "bedrooms": 3,
            "bathrooms": 2,
            "square_feet": 1800,
            "address": "456 Oak Avenue",
            "city": "San Francisco",
            "state": "CA",
            "zip_code": "94110",
            "tags": ["Recently Renovated", "Garage", "Garden"],
            "agent_name": "John Davis",
            "agency": "Golden Gate Properties"
        }
    ]
}

Extract

Learn more about our AI-powered extraction service

Python SDK

Explore our Python SDK documentation

Have a suggestion for a new example? Contact us with your use case or contribute directly on GitHub.