DEV Community

Cover image for Yahoo Finance Data API: Extract Structured JSON in 2026
AlterLab
AlterLab

Posted on • Originally published at alterlab.io

Yahoo Finance Data API: Extract Structured JSON in 2026

Yahoo Finance Data API: Extract Structured JSON in 2026

This guide covers extracting publicly accessible data. Always review a site's robots.txt and Terms of Service before scraping.

TL;DR

To get structured Yahoo Finance data via API, define a JSON schema for the fields you need (ticker, price, change_percent, volume, market_cap), then call AlterLab's Extract API with the Yahoo Finance URL and your schema. You'll receive validated, typed JSON output without writing any HTML parsers.

Why use Yahoo Finance data?

Yahoo Finance provides real-time and historical market data that powers critical financial workflows. Engineering teams use this data to:

  • Train machine learning models for stock prediction and market trend analysis
  • Build competitive intelligence dashboards that track competitor valuation metrics
  • Feed data pipelines for portfolio risk assessment and algorithmic trading systems

What data can you extract?

From publicly available Yahoo Finance quote pages, you can reliably extract these core financial fields:

  • ticker: Stock symbol (e.g., "AAPL", "MSFT")
  • price: Current trading price as a string (preserves decimal precision)
  • change_percent: Percentage price change from previous close (e.g., "+2.45%")
  • volume: Shares traded during current session (integer value)
  • market_cap: Total market capitalization (e.g., "2.8T" for trillions)

All fields are returned as strings in the JSON output to maintain exact formatting from the source, though you can cast them numerically in your application logic after validation.

The extraction approach

Direct HTTP requests to Yahoo Finance return HTML filled with dynamic content, anti-bot measures, and frequently changing class names. Parsing this with regex or CSS selectors creates fragile scrapers that break when Yahoo Finance updates its frontend.

A data API approach shifts the complexity: you specify what data you need via a JSON schema, and AlterLab handles the retrieval, JavaScript rendering, anti-bot evasion, and structured extraction. This yields consistent, typed output regardless of frontend changes—critical for production data pipelines.

Quick start with AlterLab Extract API

AlterLab's Extract API (/v1/extract) accepts a URL and JSON schema, returning validated data. See the Extract API docs for full reference.

Here's a Python example extracting Apple's quote data:

```python title="extract_yahoo-com-finance.py" {5-12}

client = alterlab.Client("YOUR_API_KEY")

schema = {
"type": "object",
"properties": {
"ticker": {
"type": "string",
"description": "The ticker field"
},
"price": {
"type": "string",
"description": "The price field"
},
"change_percent": {
"type": "string",
"description": "The change percent field"
},
"volume": {
"type": "string",
"description": "The volume field"
},
"market_cap": {
"type": "string",
"description": "The market cap field"
}
}
}

result = client.extract(
url="https://finance.yahoo.com/quote/AAPL",
schema=schema,
)
print(result.data)




The equivalent cURL request:


```bash title="Terminal"
curl -X POST https://api.alterlab.io/v1/extract \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://finance.yahoo.com/quote/AAPL",
    "schema": {
      "properties": {
        "ticker": {"type": "string"},
        "price": {"type": "string"},
        "change_percent": {"type": "string"},
        "volume": {"type": "string"},
        "market_cap": {"type": "string"}
      }
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Both examples return structured JSON like:

{
  "ticker": "AAPL",
  "price": "172.34",
  "change_percent": "+0.85%",
  "volume": "45678901",
  "market_cap": "2.7T"
}
Enter fullscreen mode Exit fullscreen mode

Define your schema

The schema parameter drives AlterLab's extraction AI. Each property defines:

  • type: Must be "string" for finance data (preserves formatting like "$" or "%")
  • description: Helps the AI locate the correct element on the page
  • Optional constraints: pattern for format validation, minimum/maximum for numeric ranges

AlterLab validates the extracted data against your schema before returning it. If the AI cannot find a field or extracts invalid data, it returns a clear error instead of malformed output—critical for pipeline reliability.

Handle pagination and scale

For bulk extraction (e.g., S&P 500 constituents), use these patterns:

  • Batching: Process 50 URLs per request using AlterLab's batch endpoint
  • Rate limiting: Stay under 10 requests/second per IP; AlterLab manages proxy rotation automatically
  • Async jobs: For >10k URLs, use the asynchronous API to avoid timeouts

Example async job submission:

```python title="batch_extract.py" {8-15}

from alterlab import BatchJob

client = alterlab.Client("YOUR_API_KEY")

urls = [f"https://finance.yahoo.com/quote/{ticker}" for ticker in sp500_tickers]
schema = {"type": "object", "properties": {"price": {"type": "string"}}}

job = client.create_batch_job(
urls=urls,
schema=schema,
webhook_url="https://yourdomain.com/webhook/alterlab"
)
print(f"Job ID: {job.id} - Status: {job.status}")




Results arrive at your webhook URL as JSON lines. Monitor usage and costs via the dashboard; detailed pricing is available at [AlterLab pricing](/pricing).

<div data-infographic="stats">
  <div data-stat data-value="99.2%" data-label="Extraction Accuracy"></div>
  <div data-stat data-value="1.4s" data-label="Avg Response Time"></div>
  <div data-stat data-value="100%" data-label="Typed JSON Output"></div>
</div>

## Key takeaways
- **Schema-first design**: Define your data structure upfront; AlterLab handles the extraction complexity
- **Compliance first**: Only extract public data; verify robots.txt and ToS for your specific use case
- **Zero maintenance**: No selector updates when Yahoo Finance changes its frontend
- **Production-ready**: Typed JSON output integrates directly with data validation tools like Pydantic
- **Cost-effective**: Pay only for successful extractions; no infrastructure to manage

<div data-infographic="steps">
  <div data-step data-number="1" data-title="Define Schema" data-description="Specify the fields you want as a JSON schema"></div>
  <div data-step data-number="2" data-title="Call Extract API" data-description="POST the URL + schema to AlterLab"></div>
  <div data-step data-number="3" data-title="Receive Typed JSON" data-description="Get back validated, structured data — no parsing needed"></div>
</div>

For immediate experimentation, try the live demo:
<div data-infographic="try-it" data-url="https://finance.yahoo.com/quote/AAPL" data-description="Extract structured finance data from Yahoo Finance"></div>

Start building your finance data pipeline today with AlterLab's Extract API—no parsing headaches, just reliable structured data.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)