Web scraping stock prices
Web scraping stock prices means collecting quotes, historical prices, fundamentals and headlines from finance portals like Yahoo Finance, Nasdaq and MarketWatch. Zenrows renders those pages, captures the JSON they load in the background or the fields you name with CSS selectors, and returns structured data for spreadsheets, dashboards and backtests.
Updated
{
"symbol": "EXMP",
"exchange": "NASDAQ",
"source_url": "https://finance.example.com/quote/EXMP",
"price": 184.27,
"change": -2.13,
"change_pct": -1.14,
"currency": "USD",
"market_state": "closed",
"quote_time": "2026-10-16T20:00:00Z",
"captured_at": "2026-10-16T20:05:31Z",
"open": 186.10,
"day_range": [182.90, 187.45],
"volume": 31842210,
"market_cap": 412500000000,
"pe_ratio_ttm": 27.4,
"eps_ttm": 6.73,
"dividend_yield": 0.0061,
"fifty_two_week_range": [141.20, 199.80],
"next_earnings_date": "2026-10-29"
}
quote_time is the portal's time for the price; captured_at is when you read the page.What stock data scraping covers
Portals spread one ticker across tabs (quote, history, statistics, news), each its own page with its own refresh rhythm.
| Job | Data you collect | Typical sources |
|---|---|---|
| End-of-day price capture | Close, open, high, low, volume | |
| Historical price tables | Daily or weekly OHLC, adjusted close, splits, dividends | |
| Fundamentals snapshots | Market cap, P/E, EPS, yield, shares outstanding | Statistics and financials tabs, Zacks, GuruFocus, Morningstar |
| Earnings and analyst calendars | Report dates, consensus, rating changes | Nasdaq earnings calendar, MarketWatch, Zacks |
| Ticker news and chatter | Headlines, timestamps, tickers, message volume | |
| Non-US listings | Local quotes, currency, exchange suffixes | finanzen.net, BSE India, |
Why stock price scrapers break
It starts as a few lines of requests and BeautifulSoup, and breaks when the portal moves the price to a background call or challenges repeat visitors.
Layout but no price, or a placeholder dash
A full render with XHR capture returns the page plus the quote data
Some countries get a cookie consent page instead
Geotargeting picks the market; page actions click through consent
429s or challenges after hundreds of requests from one IP
Zenrows' stealth keeps polling unblocked; Batch runs the list as one job
Strings like "412.5B", "N/A" or "-1.14%"
CSS selectors return exactly those cells, for one parsing function
A redesign renames classes; selectors return nothing
Extract returns JSON without selectors
A delayed quote stored as live
Store the portal's quote time with your capture time
How to scrape stock prices with Zenrows
- List the tickers and pages: quote, history and statistics URLs from each portal's pattern.
- Capture the quote data: full render with network capture; keep the call carrying the price.
- Name fields where the HTML is enough: CSS selectors for statistics and calendars, with Adaptive Stealth Mode for access.
- Run the watchlist after the close in Batch, daily or at your dashboard's interval.
- Validate before storing against the previous day and a reference close.
# pip install requests
import json
import requests
params = {
"apikey": "YOUR_ZENROWS_API_KEY",
"url": QUOTE_URL, # a portal's quote page for one ticker
"js_render": "true",
"premium_proxy": "true",
"json_response": "true",
}
data = requests.get("https://api.zenrows.com/v1/", params=params).json()
# The page loads the price in a background call; keep the one that holds it
for call in data["xhr"]:
if "quote" in call["url"] and call["status_code"] == 200:
print(json.loads(call["body"]))curl -G "https://api.zenrows.com/v1/" \
--data-urlencode "apikey=YOUR_ZENROWS_API_KEY" \
--data-urlencode "url=STATISTICS_URL" \
--data-urlencode "mode=auto" \
--data-urlencode 'css_extractor={"market_cap":"[data-field=marketCap]","pe_ratio":"[data-field=peRatio]","dividend_yield":"[data-field=dividendYield]"}'npx -y @zenrows/cli init
zenrows extract https://finance.yahoo.com/quote/AAPL/history/ --outputs tables
zenrows extract https://finance.yahoo.com/quote/AAPL/key-statistics/ --autoparse
# watchlist.jsonl: one {"url": "..."} per quote or history page
zenrows batch create watchlist.jsonl --wait# Connect once
claude mcp add zenrows -e ZENROWS_API_KEY=YOUR_ZENROWS_API_KEY -- npx -y @zenrows/mcp
# Then ask:
Use Zenrows to read the Yahoo Finance quote pages for AAPL, MSFT and NVDA and return a JSON list with ticker, last price, change percent, market cap, P/E ratio and the quote time shown on each page.Which Zenrows product fits
- Read one quote page with background-loaded data FetchXHR calls plus the rendered HTML
- Get history tables or stats without selectors ExtractJSON that adapts when the layout changes
- Refresh hundreds of tickers daily BatchOne job, results by webhook
- Try a page from the terminal first CLIThe page as JSON or Markdown in one command
What success looks like
| Measure | What good looks like | How to check it |
|---|---|---|
| Price accuracy | Closes match the official close | Weekly reconcile of a random sample |
| Ticker coverage | Every symbol, every trading day | Missing symbol-date pairs per run |
| Timestamp hygiene | Quote time and capture time on each record | Reject empty or unexpectedly old quote times |
| Parse rate | Clean numbers; "N/A" and dashes as nulls | Type-check failures per portal |
| Run time | Done well before the dashboard or backtest reads it | Batch start and finish against ticker count |
Web scraping stock prices FAQ
-
Yes. Yahoo Finance loads parts of its quote pages with JavaScript, so render them and capture the background calls, including the one carrying the quote. Zenrows' stealth keeps requests going across many tickers. The same works for Nasdaq.com, MarketWatch and most portals.
-
Public portal prices are widely used for personal research and internal analysis. Redistribution differs: exchange data is licensed and portal terms often restrict commercial reuse. Check each site's terms and licensing, and ask your legal team before publishing or reselling.
-
Open the ticker's history page with the date range in the URL and use Extract or the tables output filter for JSON rows. Backfill once, then append daily. Store splits and dividends, often in the same table, as separate events.
-
You set the interval: every few minutes intraday, daily for research. Many portals show delayed quotes and say so, so store the quote time. End-of-day after the close is the most common schedule.
-
Call the Zenrows API with
requests, the quote URL and the parameters above, and read the JSON. Zenrows handles rendering, stealth and retries; your code builds URLs, parses fields and stores rows. Past a few hundred tickers, use Batch. -
Use the symbol's news tab, on Yahoo Finance or MarketWatch for example. Fetch it as Markdown or name headline, source, link and time with CSS selectors; store each with ticker and capture time, deduplicated on article URL since stories repeat across portals.
-
Yes. Statistics, financials and earnings calendars are separate URLs per ticker. Use CSS selectors or Extract, and store dated snapshots: market cap and P/E change daily.