Skip to content

callanjfox/realestate-scraping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real Estate Scraper - XPath-Based Property Extraction

A comprehensive web scraper for realestate.com.au that extracts complete property data using precise XPath selectors and hybrid extraction methods. Successfully bypasses Kasada protection using ScrapingBee service with intelligent container-based data extraction.

✅ Current Status

WORKING SOLUTION: XPath-Based Extraction

  • Success Rate: 100% data extraction from accessible pages
  • Performance: ~3-4 seconds per property
  • Cost: ~75 ScrapingBee credits per property
  • Data Quality: Comprehensive property details including features and highlights

🎯 What This Scraper Extracts

Core Property Data:

  • Property address and ID
  • Bedrooms, bathrooms, car spaces
  • Land size and property type
  • Offer/price information

Detailed Information:

  • Property highlights (8+ items)
  • Property features (20+ items including sheds, pools, etc.)
  • Full property description
  • Inspection times

Agent & Agency Details:

  • Agent name and photo
  • Agent contact number
  • Agency name and address

Media:

  • 30+ high-quality property images
  • Main photo and thumbnail variants

🚀 Quick Start

1. Installation

# Install dependencies
pip install scrapingbee lxml beautifulsoup4 requests pathlib

# Or use requirements if available
pip install -r requirements.txt

2. Get ScrapingBee API Key

  1. Visit: https://www.scrapingbee.com/
  2. Sign up for trial (1000 credits) or paid plan
  3. Get API key from dashboard
  4. Update the API key in both property_listings_scraper.py and refined_xpath_extractor.py

3. Run Incremental Sync (RECOMMENDED)

# Run complete two-stage incremental sync
python3 incremental_property_scraper.py

# This will:
# 1. Scrape Brisbane listings (150+ properties per 2 pages)
# 2. Filter out already-scraped properties
# 3. Extract detailed data for new properties only
# 4. Download images automatically
# 5. Track progress for resume capability

4. Alternative: Single Property

# Extract specific property with full details
python3 refined_xpath_extractor.py

# Check extracted data
cat data/properties/149008036_refined_complete.json

# View images
ls data/images/149008036/

📁 Project Structure

├── incremental_property_scraper.py  # 🎯 MAIN WORKFLOW (USE THIS)
├── property_listings_scraper.py     # Stage 1: Extract property URLs from listings
├── refined_xpath_extractor.py       # Stage 2: Extract detailed property data
├── scraper.py                       # Legacy Playwright-based scraper
├── incremental_sync.py              # Legacy sync functionality
├── main.py                          # CLI interface for legacy scraper
├── test_connection.py               # Test ScrapingBee connectivity
├── test_scraper.py                 # Test suite
├── archive_experimental/            # Experimental scripts (archived)
├── data/
│   ├── tracking/                   # Sync state and property ID tracking
│   ├── listings/                   # Raw listing page HTML (debugging)
│   ├── properties/                 # Extracted property JSON files
│   ├── images/                     # Downloaded property images
│   ├── html_inspection/            # Raw HTML for debugging
│   └── logs/                       # Legacy scraper logs
├── TWO_STAGE_WORKFLOW.md           # Complete workflow documentation
├── CLAUDE.md                       # Developer instructions
└── README.md                       # This file

🔄 Two-Stage Workflow (RECOMMENDED)

Stage 1: Listings Scraper

Automatically finds property URLs from Brisbane search results:

  • Scrapes: https://www.realestate.com.au/buy/property-house-in-brisbane+-+greater+region,+qld/list-1
  • Finds: 150+ property URLs per 2 pages
  • Handles: Pagination automatically
  • Extracts: Property IDs for tracking

Stage 2: Detail Extractor

Extracts comprehensive data for each property:

  • Uses: Your exact XPath selectors
  • Extracts: 20+ fields per property
  • Downloads: Property images automatically
  • Tracks: Scraped property IDs for incremental sync

Incremental Sync Benefits

  • No duplicates: Only scrapes new properties
  • Resume capability: Can stop and restart safely
  • Cost efficient: Only uses API credits for new properties
  • Fresh data: Always gets latest listings

🔧 Usage Examples

Incremental Sync (Main Workflow)

# Run complete incremental sync
python3 incremental_property_scraper.py

# Check results
ls data/properties/          # Property JSON files
ls data/images/             # Downloaded images
cat data/tracking/sync_log.json  # Sync history

Basic Property Extraction

from refined_xpath_extractor import RefinedXPathExtractor

# Initialize extractor
extractor = RefinedXPathExtractor()

# Extract property data
property_url = "https://www.realestate.com.au/property-house-qld-wilston-149008036"
success, data = extractor.extract_property_refined(property_url)

if success:
    print(f"Extracted {len(data)} fields")
    print(f"Property: {data['title']}")
    print(f"Price: {data['offer']}")
    print(f"Features: {len(data['property_features'])} items")

Batch Processing

# Multiple properties
property_urls = [
    "https://www.realestate.com.au/property-house-qld-wilston-149008036",
    "https://www.realestate.com.au/property-apartment-qld-south+bank-148928524"
]

for url in property_urls:
    success, data = extractor.extract_property_refined(url)
    if success:
        print(f"✅ Extracted: {data['title']}")
    else:
        print(f"❌ Failed: {url}")

📊 Data Output Format

{
  "id": "149008036",
  "title": "13 Noble Street, Wilston, Qld 4051",
  "offer": "Offers over $1.25M",
  "bedrooms": 3,
  "bathrooms": 2,
  "car_spaces": 3,
  "land_size": "607m²",
  "property_features": [
    "Land size: 607m²",
    "Air conditioning",
    "Dishwasher",
    "Study",
    "Balcony",
    "Deck",
    "Outdoor entertaining area",
    "Shed"
  ],
  "property_highlights": [
    "Renovated stone kitchen with stone benchtops, new 2pac cupboards, and polished timber floors",
    "Lower level potential - 2 multi-purpose rooms, bathroom, kitchen space; scope for legal height",
    "Prime Wilston location - Walk to schools, bus/train, Downey Park; short bike ride to CBD"
  ],
  "agent_name": "Ben Jackson",
  "agent_number": "0411015242",
  "agency_name": "Metrocity Realty",
  "description_body": "Full property description...",
  "images": [
    {
      "url": "https://i2.au.reastatic.net/800x600/...",
      "type": "main_photo"
    }
  ]
}

⚙️ Technical Implementation

XPath-Based Extraction

The scraper uses precise XPath selectors to target specific data containers:

# Working XPath examples
working_xpaths = {
    'full_address': '/html/body/div[1]/div[4]/div[3]/div[1]/div/div/div[1]/div/div[1]/div[1]/h1',
    'bedrooms': '/html/body/div[1]/div[4]/div[3]/div[1]/div/div/div[1]/div/div[1]/div[2]/ul/div[1]/li[1]/p',
    'offer': '/html/body/div[1]/div[4]/div[3]/div[1]/div/div/div[1]/div/div[2]/span'
}

# Container XPaths for complex data
container_xpaths = {
    'property_highlights': '/html/body/div[1]/div[4]/div[3]/div[2]/div[1]/div/div/div[4]/div[3]',
    'property_features': '/html/body/div[1]/div[4]/div[3]/div[2]/div[1]/div/div/div[6]/div/div/div'
}

Hybrid Extraction Strategy

  1. Direct XPath Extraction: For simple fields (bedrooms, price, etc.)
  2. Container Extraction: For complex lists (features, highlights)
  3. Meta Tag Fallbacks: For descriptions and images
  4. Intelligent Sub-extraction: Parse containers for individual items

ScrapingBee Configuration

params = {
    'render_js': True,           # Execute JavaScript
    'block_resources': False,    # Load all resources
    'stealth_proxy': True,       # Bypass Kasada protection
    'country_code': 'AU'         # Australian IP addresses
}

💰 Cost Analysis

ScrapingBee Usage:

  • Cost per property: ~75 credits
  • Trial (1000 credits): ~13 properties
  • Freelance plan (100k credits): ~1,333 properties
  • Performance: 3-4 seconds per property

🛠️ Configuration

API Key Setup

Edit refined_xpath_extractor.py and update:

def __init__(self):
    self.api_key = "YOUR_SCRAPINGBEE_API_KEY_HERE"

Customizing Target Location

Modify the test URL in the script:

test_url = "https://www.realestate.com.au/property-house-qld-wilston-149008036"

Adjusting Extraction Limits

# In extraction methods
property_data['property_features'] = features[:20]  # Limit features
property_data['property_highlights'] = highlights[:8]  # Limit highlights

🐛 Troubleshooting

ScrapingBee Issues

HTTP 401: Invalid API key

# Check API key in refined_xpath_extractor.py

HTTP 429: Rate limiting

# Enable stealth_proxy in params

Missing Data: XPath may have changed

# Check data/html_inspection/ for raw HTML
# Update XPath selectors if needed

Data Quality Issues

Empty property_features/highlights: Page structure changed

  • Check if containers exist with different XPaths
  • Fallback methods will still extract from descriptions

Missing agent_number: Phone number location varies

  • Multiple extraction methods implemented
  • May not be publicly displayed on all listings

📋 Legacy Files

The repository includes legacy approaches for reference:

  • scraper.py - Original Playwright-based scraper
  • main.py - CLI interface for legacy system
  • incremental_sync.py - Sync functionality
  • archive_experimental/ - All experimental approaches

🔄 Incremental Scraping

For ongoing data collection:

# Legacy system with incremental updates
python3 main.py sync

# Periodic sync (every 24 hours)
python3 main.py periodic --interval 24

📈 Scaling Up

Multiple Properties

  1. Get property URLs from search pages
  2. Run extraction in batches to manage API costs
  3. Implement delays between requests
  4. Save progress to handle interruptions

Production Deployment

  1. Set up monitoring for XPath changes
  2. Implement data validation
  3. Add image download functionality
  4. Set up automated scheduling

🔒 Legal and Ethical Use

  • Public Data Only: Scrapes publicly available property listings
  • Respectful Usage: Appropriate delays between requests
  • Commercial Service: Uses legitimate ScrapingBee service
  • Terms Compliance: For research and legitimate business use

🎯 Success Metrics

  • XPath Success Rate: 15/17 selectors working (88%)
  • Data Completeness: 23 fields extracted per property
  • Image Collection: 30+ images per property
  • Container Extraction: 100% success on target fields

✅ READY TO USE: This scraper provides comprehensive property data extraction with proven XPath selectors and robust fallback methods.

About

Advanced web scraper for realestate.com.au with anti-bot protection, proxy support, and optimized performance

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors