For most Yahoo Finance Python projects, start with yfinance for historical prices and company data. Use BeautifulSoup when you need a specific table from an authorized HTML capture. In both cases, check the instrument, currency, dates and adjustment settings before exporting data: a successful request does not necessarily produce a usable market-data record.
This guide is for developers working with daily equity prices and authorized saved HTML tables. It includes a CSV downloader, a saved-HTML parser, explicit failure handling and practical proxy configuration. Company profiles, financial statements and total-return portfolio calculations are outside the implemented tutorial. The network route is one part of that pipeline; it cannot correct a wrong ticker, grant data rights or turn delayed quotes into an execution feed.
Quick answer
- Use
Ticker.history()for one instrument and the optionaldownload()example for multiple instruments; validate each ticker separately. - Confirm permission for automated access and data reuse before any source request; an open-source client is not a data license.
- Set adjustment and date-window options explicitly; do not depend on library defaults.
- Save currency, exchange timezone, collection time and software versions alongside CSV data.
- Treat missing tables, empty frames and 429 responses as distinct failures, not empty successful exports.
- Use a proxy only when an authorized collection workflow needs its routing or session controls.
Choose the right Yahoo Finance Python method
| Requirement | Starting point | What to check |
|---|---|---|
| Daily historical OHLCV for one equity | yf.Ticker(symbol).history() |
Symbol, date bounds, adjustment mode, currency and timezone |
| Several instruments over one window | yf.download() |
MultiIndex layout, failed tickers and per-symbol completeness |
| A table present in saved HTML | BeautifulSoup | Correct table identity, headers, row count and raw units |
| A JavaScript-only page section, outside this parser | A permitted export/product or separately authorized browser capture | BeautifulSoup cannot execute JavaScript or recover fields absent from the saved HTML |
| Production redistribution or trading-critical data | A licensed data service | Usage rights, exchange coverage, delay, corrections and service commitments |
yfinance is an independent open-source project, not an official Yahoo-supported API contract. Its maintainers describe research and educational use and direct users to Yahoo’s terms for data rights. An open-source library’s license does not license the underlying market data. Check the intended use separately, especially for commercial storage or redistribution. Project information

How to download data from Yahoo Finance using Python
Confirm data-access permission first
Yahoo’s Terms of Service restrict automated access or collection without express prior permission and also address commercial reuse. Before using the network examples, confirm that the specific page or interface, account, purpose and applicable jurisdiction permit the access method and intended reuse. A successful response, an open-source software license or a proxy subscription does not grant data rights.
If permission is unclear, work with a user-provided export, a Yahoo-provided product whose terms permit the use, or a financial-data provider licensed for the intended purpose. Yahoo Finance’s robots.txt supplies path rules, not permission or a substitute for the terms; its official URL is in the source table below.
After confirming permission, begin with one symbol and a small daily window. This makes it easier to identify a connection or data-shape problem before expanding a job. The saved synthetic examples later in this tutorial require no Yahoo request.
1. Create one environment
The examples target yfinance==1.8.0, the release listed by the project on November 18, 2026. Pinning it avoids silently following an older tutorial’s API. Use the same interpreter for installation and execution. Release notes
Windows PowerShell:
py -m venv .venv
.\.venv\Scripts\python.exe -m pip install "yfinance==1.8.0" "beautifulsoup4==4.15.0" "requests[socks]==2.34.2"
.\.venv\Scripts\python.exe -m pip freeze > requirements-lock.txt
macOS/Linux:
python3 -m venv .venv
.venv/bin/python -m pip install "yfinance==1.8.0" "beautifulsoup4==4.15.0" "requests[socks]==2.34.2"
.venv/bin/python -m pip freeze > requirements-lock.txt
The lock file records transitive dependencies too. Keep it with the job rather than assuming that the same top-level library version guarantees an identical environment forever.
2. Fetch a small historical window
import yfinance as yf
yf.config.network.retries = 0
yf.config.debug.hide_exceptions = False
ticker = yf.Ticker("AAPL")
prices = ticker.history(
start="2026-11-02", end="2026-11-07", interval="1d",
auto_adjust=False, actions=True, repair=False,
keepna=True, timeout=20,
)
if prices.empty:
raise ValueError("empty_history")
print(prices[["Open", "High", "Low", "Close", "Adj Close", "Volume"]])
The end date is exclusive: this request asks for trading observations before November 7, not through November 7. Non-trading days need not have rows. A daily time window is not a promise of one observation for every calendar date. The package documents date bounds, intervals and download options in its download reference.
auto_adjust=False keeps Close and Adj Close distinct. Adjusted series account for corporate-action effects according to the source’s methodology; they are not an alternative name for the same raw close. Keep adjustment settings consistent across a backtest. repair=False avoids silently requesting the package’s optional repair behavior, while keepna=True lets validation expose incomplete rows.
Company profiles and statements require different contracts from daily bars. The Ticker reference is a follow-up resource for those methods, not an additional implemented route here. Adding another wrapper such as yahoofinancials is unnecessary for this tutorial’s daily-price scope; evaluate its maintenance, access method and data contract separately if a requirement genuinely calls for it.
The pinned version recommends yf.config.debug.hide_exceptions = False rather than passing the deprecated per-call error flag. Its 1.8.0 history implementation documents that migration. Configure this before requesting data. Library/request failures are different from a local ValueError rejecting an invalid row; neither should become an empty successful export.

3. Export history with context and validation
The complete helper below saves history.csv only after checking its required fields, dates, finite numbers, equity-price relationships and instrument context. It also writes audit.json with the currency, exchange timezone, version numbers and CSV hash. Use a fresh output directory for each run so old data cannot masquerade as a new download.
Save the following code as yahoo_finance_tools.py. It includes both the historical downloader and the saved-table parser used later.
Complete Python helper: download, validate and parse
"""Small Yahoo Finance research helpers. Network calls are explicit, never on import."""
import csv
import hashlib
import json
import math
from datetime import date, datetime, timezone
from importlib.metadata import version
from pathlib import Path
def validate_bars(rows, start, end):
required = {"Date", "Open", "High", "Low", "Close", "Adj Close", "Volume"}
if not rows:
raise ValueError("empty_history")
seen = set()
previous = None
for row in rows:
if not required.issubset(row):
raise ValueError("missing_column")
day = date.fromisoformat(str(row["Date"])[:10])
if not date.fromisoformat(start) <= day < date.fromisoformat(end):
raise ValueError("date_outside_range")
if day in seen or (previous is not None and day <= previous):
raise ValueError("duplicate_or_unsorted_date")
seen.add(day)
previous = day
values = {k: float(row[k]) for k in required - {"Date"}}
if not all(math.isfinite(v) for v in values.values()):
raise ValueError("nonfinite_value")
if any(values[k] <= 0 for k in ("Open", "High", "Low", "Close", "Adj Close")):
raise ValueError("nonpositive_equity_price")
if (values["Low"] > min(values["Open"], values["Close"])
or values["High"] < max(values["Open"], values["Close"])
or values["Low"] > values["High"]):
raise ValueError("ohlc_inconsistent")
if values["Volume"] < 0 or not values["Volume"].is_integer():
raise ValueError("invalid_volume")
return rows
class HistoryDownloadError(RuntimeError):
"""Source/library failure, distinct from local record-validation errors."""
def download_history(symbol, start, end, output_dir, expected_currency, expected_timezone):
import yfinance as yf
yf.config.network.retries = 0
yf.config.debug.hide_exceptions = False
out = Path(output_dir)
if out.exists():
raise ValueError("choose_fresh_output_directory")
try:
ticker = yf.Ticker(symbol)
frame = ticker.history(start=start, end=end, interval="1d", auto_adjust=False,
actions=True, repair=False, keepna=True, timeout=20)
meta = ticker.history_metadata
except Exception:
raise HistoryDownloadError("history_request_failed") from None
if (meta.get("symbol") != symbol or meta.get("currency") != expected_currency
or meta.get("exchangeTimezoneName") != expected_timezone):
raise ValueError("instrument_context_mismatch")
frame = frame.reset_index()
if "Date" not in frame:
raise ValueError("daily_date_column_missing")
frame["Date"] = frame["Date"].map(lambda value: value.isoformat())
rows = validate_bars(frame.to_dict("records"), start, end)
out.mkdir(parents=True)
frame.to_csv(out / "history.csv", index=False)
audit = {"symbol": symbol, "start_inclusive": start, "end_exclusive": end,
"interval": "1d", "auto_adjust": False, "repair": False,
"currency": meta["currency"], "exchange_timezone": meta["exchangeTimezoneName"],
"rows": len(rows), "retrieved_utc": datetime.now(timezone.utc).isoformat(),
"yfinance_version": version("yfinance"), "pandas_version": version("pandas"),
"csv_sha256": hashlib.sha256((out / "history.csv").read_bytes()).hexdigest(),
"status": "structure_and_equity_bar_checks_passed"}
(out / "audit.json").write_text(json.dumps(audit, indent=2), encoding="utf-8")
print(json.dumps({"rows": len(rows), "file": str(out / "history.csv")}, indent=2))
def parse_quote_table(html):
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
candidates = []
wanted = ["Symbol", "Name", "Price"]
for table in soup.find_all("table"):
header_row = table.find("tr")
headers = [cell.get_text(" ", strip=True) for cell in header_row.find_all("th")] if header_row else []
if headers == wanted:
candidates.append(table)
if len(candidates) != 1:
raise ValueError("missing_or_ambiguous_quote_table")
records = []
seen = set()
for tr in candidates[0].find_all("tr")[1:]:
cells = tr.find_all("td", recursive=False)
if not cells:
continue
if len(cells) != len(wanted):
raise ValueError("quote_column_count")
record = dict(zip(wanted, [cell.get_text(" ", strip=True) for cell in cells]))
if any(not value for value in record.values()) or record["Symbol"] in seen:
raise ValueError("empty_or_duplicate_quote")
seen.add(record["Symbol"])
records.append(record)
if not records:
raise ValueError("empty_quote_table")
return records
def export_quote_table(input_file, output_file):
records = parse_quote_table(Path(input_file).read_text(encoding="utf-8"))
with Path(output_file).open("x", newline="", encoding="utf-8") as target:
writer = csv.DictWriter(target, fieldnames=["Symbol", "Name", "Price"])
writer.writeheader()
writer.writerows(records)
print(json.dumps({"rows": len(records), "file": output_file}))
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
modes = parser.add_subparsers(dest="mode", required=True)
history = modes.add_parser("history")
for field in ("symbol", "start", "end", "output_dir", "expected_currency", "expected_timezone"):
history.add_argument(field)
table = modes.add_parser("table")
table.add_argument("input_file")
table.add_argument("output_file")
args = vars(parser.parse_args())
mode = args.pop("mode")
try:
(download_history if mode == "history" else export_quote_table)(**args)
except Exception as exc:
# Avoid publishing request URLs, cookies, proxy credentials or response bodies.
safe = str(exc) if type(exc) is ValueError and str(exc).replace("_", "").isalnum() else type(exc).__name__
print("Stopped: " + safe)
raise SystemExit(1)
Run the historical route in PowerShell:
.\.venv\Scripts\python.exe .\yahoo_finance_tools.py history AAPL 2026-11-02 2026-11-07 .\aapl-run-001 USD America/New_York
On macOS/Linux:
.venv/bin/python yahoo_finance_tools.py history AAPL 2026-11-02 2026-11-07 aapl-run-001 USD America/New_York
The expected currency and timezone are deliberate input checks, not facts inferred from the exit IP. When the source metadata disagrees, the helper stops instead of relabeling data. Its validation is scoped to ordinary positive-price daily equities; adapt the contract for instruments whose price or volume conventions differ. A valid bar does not establish exchange accuracy or complete corporate-action treatment.

Figure 3. The example window excludes November 7. Included dates illustrate the request bounds, not observed trading rows.
Optional: download two tickers and select MultiIndex columns
After confirming the same access permission, this structural example requests one daily window with explicit column grouping and no threaded fan-out:
import pandas as pd
import yfinance as yf
from yahoo_finance_tools import validate_bars
yf.config.network.retries = 0
yf.config.debug.hide_exceptions = False
start, end = "2026-11-02", "2026-11-07"
prices = yf.download(
["AAPL", "MSFT"], start=start, end=end, interval="1d",
auto_adjust=False, actions=True, keepna=True, repair=False,
group_by="column", multi_level_index=True, ignore_tz=False,
threads=False, progress=False, timeout=20,
)
if prices is None or prices.empty:
raise ValueError("empty_download")
if not isinstance(prices.columns, pd.MultiIndex) or "Ticker" not in prices.columns.names:
raise ValueError("unexpected_columns")
checked = {}
for symbol in ("AAPL", "MSFT"):
if symbol not in prices.columns.get_level_values("Ticker"):
raise ValueError("missing_ticker")
one = prices.xs(symbol, axis=1, level="Ticker").copy()
required = ["Open", "High", "Low", "Close", "Adj Close", "Volume"]
if not set(required).issubset(one.columns):
raise ValueError("missing_column")
one = one[required].reset_index()
if "Date" not in one:
raise ValueError("daily_date_column_missing")
one["Date"] = one["Date"].map(lambda value: value.isoformat())
checked[symbol] = validate_bars(one.to_dict("records"), start, end)
print({symbol: len(rows) for symbol, rows in checked.items()})
The parameters are matched to the pinned batch implementation. checked contains per-symbol structurally checked rows, not final business acceptance or an observed download result. Validate returned instrument/currency metadata and the intended exchange-session calendar before exporting them. This strict example rejects null rows; differing exchange calendars need an explicit missing-session policy rather than blanket forward-filling. A combined nonempty frame never proves every ticker succeeded.
Parse an authorized saved HTML table
For web scraping Yahoo Finance Python, the example here is a saved-HTML parser unit test, not a capture of a current Yahoo table. Use it with a document you are authorized to access and save. First inspect status, redirects, Content-Type and the saved response HTML, not only the browser’s rendered DOM. A table visible after JavaScript executes may be absent from that document.
Choose the data path before choosing a parser:
| Decision | Route |
|---|---|
| No permission for automatic access or reuse | Stop network collection; use an approved export or licensed product |
| Permission confirmed and structured historical data meets the requirement | Use the pinned history/batch route and validate the result |
| Authorized saved HTML contains one identifiable target table | Inspect headers and units, then parse and export |
| Authorized HTML contains the needed data only as embedded JSON | Parse only the permitted response’s identified JSON structure; verify symbol, schema and units |
| Neither the static table nor needed JSON is in the permitted document | Use a permitted export/product or a separately authorized rendering workflow; do not report empty parser output as data |
Embedded JSON can be more appropriate than visual table cells when an authorized document already includes a structured payload. It is not a reason to guess private endpoint URLs, reuse another account’s cookies or fetch undisclosed resources. Inspect the actual saved document and pin its contract; no current Yahoo JSON selector is assumed here.
Do not begin with a CSS class copied from an old tutorial. Save a permitted page capture, identify its intended table, and compare headers before processing rows. Yahoo can change markup, labels and rendering. A parser should stop when its contract no longer matches, rather than returning zero rows as a successful scrape.
Run a reproducible saved-HTML example
Create sample_quotes.html with this small synthetic table. These are parser inputs, not stock quotes or a Yahoo response:
<table>
<tr><th>Symbol</th><th>Name</th><th>Price</th></tr>
<tr><td>TEST-A</td><td>Example Alpha</td><td>18.50</td></tr>
<tr><td>TEST-B</td><td>Example Beta</td><td>25.00</td></tr>
</table>
Then run the table route from the same helper:
.\.venv\Scripts\python.exe .\yahoo_finance_tools.py table .\sample_quotes.html .\sample_quotes.csv
On macOS/Linux, replace the interpreter and paths with .venv/bin/python yahoo_finance_tools.py table sample_quotes.html sample_quotes.csv. The output file must not already exist.
The executed parser produced two records:
Symbol,Name,Price
TEST-A,Example Alpha,18.50
TEST-B,Example Beta,25.00
This parser deliberately accepts exactly one table with the Symbol, Name, Price header contract. It preserves price text instead of guessing whether 1,250, 1.250, a currency symbol or a pence quote needs conversion. For an authorized Yahoo capture, inspect the real headers and update the contract explicitly; the synthetic header set is not a claim about today’s Yahoo page structure.
Keep the original HTML, URL, UTC capture time, displayed currency/unit and exchange context beside the export. If two tables match, the parser rejects the document. That protects against taking a navigation widget or unrelated market table as the requested data.

Requests, BeautifulSoup and dynamic content
BeautifulSoup parses HTML; it does not run JavaScript or fetch a page by itself. Requests fetches the HTTP response. Keep these steps separate so a rejected request cannot be mistaken for an HTML-selector failure.
For an approved HTML source, check status and MIME type before parsing, cap the body size and set timeouts. Stop on 403, 429, a challenge page or an unexpected redirect. A consent page with HTTP 200 is still not the requested quote table. Do not solve every missing selector by adding a browser: first establish whether the response is the intended document.
An authorized Playwright or Selenium capture can help when a required section is genuinely rendered client-side. It adds browser resource costs and another set of failure modes. Our stock-price scraping guide covers the broader collection and validation workflow; use the lightest permitted method that supplies the required fields.
What the practical checks returned
On November 18, 2026, a default Requests GET to the AAPL quote page returned this result:
HTTP status: 429
Content-Type: text/html
Response body bytes: 23
Body: Edge: Too Many Requests
Action: stop; no retry or route change
This is a historical diagnostic observation, not a step to repeat or evidence of source permission. The request failed before any quote-table parsing occurred. Its response alone cannot identify whether the decision depended on the client, shared network history or another server-side rule. It does not prove a permanent IP ban or establish a universal requests-per-minute threshold. Do not change exits to defeat the refusal.
The parsing and validation run used Python 3.12.14, BeautifulSoup 4.15.0 and Requests 2.34.2. Its 17 deterministic checks passed:
| Check group | Executed result |
|---|---|
| Two-row synthetic HTML → CSV | Two records exported with the stated headers |
| Empty history or missing close | Rejected |
| NaN, negative equity price or inconsistent OHLC | Rejected |
| Negative/fractional volume | Rejected |
| Duplicate, unsorted or exclusive-end date | Rejected |
| Missing/ambiguous table, changed header or malformed row | Rejected |
| Duplicate quote symbol | Rejected |
These results establish the helper’s data gates. The synthetic TEST-A and TEST-B records remain separate from downloaded market data, and the historical-download path keeps its own instrument and dependency audit.

Fix 429 errors without confusing the failing layer
A reliable Python web scraping Yahoo Finance workflow distinguishes authentication, throttling, transport and data-contract failures. Changing the route before making that distinction can conceal the cause and leave the dataset wrong.
| Symptom | Likely area to inspect | Next action |
|---|---|---|
| HTTP 429 | Source throttling/client or shared-route policy | Stop the batch; consider Retry-After only if supplied and the access itself is permitted |
| HTTP 401 | Authentication or changed endpoint requirements | Check library version and documented access; do not copy unrelated cookies |
| HTTP 403 or CAPTCHA | Access refusal/challenge | Stop or use an approved source; do not cycle identities to defeat refusal |
| Proxy 407 | Proxy authentication | Check the generated proxy user, password and selected protocol port |
| TLS or connection timeout | Trust store, gateway, DNS or network | Verify certificates and endpoint settings; do not disable TLS verification |
| Empty history | Symbol, date window, market closure or upstream failure | Check the instrument and recorded error before accepting an empty file |
| Table missing with HTTP 200 | Consent page, changed markup or client rendering | Inspect the saved response and headers |
| Price off by 100× | Currency unit, pence/cents or source correction | Review raw values and units before normalizing |
There is no safe, universal Yahoo quota established by a successful small request. Cache completed daily windows, request only missing data, avoid needless .info calls and use a bounded queue. Keep a batch-level stop condition so a library’s empty result cannot cause hundreds of follow-on requests. Retry only when appropriate for the response and permitted workflow—not indefinitely.
Configure Socks5.IO for an authorized collection route
A residential proxy is useful when a job whose access method and data reuse are permitted by applicable terms or explicit authorization requires a particular route or consistent session context. Internal approval of a project alone is not source permission. The proxy does not change Yahoo’s terms, exchange licensing, token/cookie requirements or the meaning of a financial field. If ordinary permitted access or an approved export already meets the requirement, there is no reason to add proxy complexity.
Socks5.IO’s relevant controls are product-specific proxy credentials, location selection and sticky versus rotating routing. Use Rotating Residential IP → Buy to select a product, Sub-account Management → Add to create a traffic-limited proxy user, and the product’s Proxy Setup page to generate connection fields. The console login and proxy authentication account are different credentials.


Requests configuration
Install requests[socks], then load the complete generated URL from your existing secret manager as SOURCE_PROXY_URL. Do not paste credentials into a shared command, notebook output or screenshot.
import os
from urllib.parse import urlsplit
import requests
proxy_url = os.environ["SOURCE_PROXY_URL"]
parts = urlsplit(proxy_url)
if parts.scheme not in {"http", "socks5h"} or not parts.hostname or not parts.port:
raise ValueError("invalid_proxy_configuration")
client = requests.Session()
client.trust_env = False
client.proxies.update({"http": proxy_url, "https": proxy_url})
That configuration attaches the route only to this client; it does not send a Yahoo request. For Requests, socks5h:// delegates destination DNS resolution to the proxy, while socks5:// uses local resolution. An HTTP proxy can tunnel HTTPS traffic using CONNECT. Neither protocol name establishes a speed or anonymity winner. See the Requests proxy documentation.
Before an approved source request, make a single diagnostic request to an IP-information service using the same client and inspect the reported country. In sticky mode, bracket a related flow with diagnostics to detect changes. Those diagnostics are separate requests, not proof of the source request’s exact exit; verify application-level context too. Keep full IPs and credentials in restricted logs, not the public article.
yfinance configuration is different
For the pinned version, use its configuration object rather than an obsolete Ticker(..., proxy={...}) example:
import os
import yfinance as yf
yf.config.network.proxy = os.environ["SOURCE_PROXY_URL"]
yf.config.network.retries = 0
yf.config.debug.hide_exceptions = False
# Make an approved history request only after endpoint and access checks.
Apply that setting before creating a ticker or starting workers. It is package-wide configuration, not a per-record proxy switch; use a separate process if different jobs require different routes. The pinned yfinance configuration source defines the network proxy setting. Verify that the selected transport supports the generated protocol and port; Requests support does not automatically establish another HTTP backend’s compatibility.
Keep one sticky route for related cookie-dependent steps. Independent permitted observations may use rotating routing, but do not rotate midway through a flow or after an access refusal to manufacture a fresh identity. Country selection alone does not change a ticker’s exchange, quote currency or data rights.

Build a dataset you can audit
For each acquisition, keep a compact record of what the data means:
| Record | Why it matters |
|---|---|
| Requested and returned symbol; exchange | Similar labels, renamed tickers and different listings are not interchangeable |
| Currency and quote unit | USD, GBP and pence values must not be compared as the same unit |
| Interval and exchange timezone | Daily sessions differ from UTC calendar dates and intraday timestamps |
| Start-inclusive/end-exclusive window | Explains expected coverage without inserting weekend prices |
| Adjustment, action and repair settings | Prevents a quiet change in the series definition |
| Retrieval UTC, library versions and file hash | Makes a saved observation traceable and detects later file changes |
| Status, missing rows and review decision | Separates a completed file from usable research data |
The helper requests source action columns, but it does not calculate portfolio total return: dividends, reinvestment, splits and cash-flow timing need their own model. Financial statements and intraday collection are outside the implementation here. If you extend it, keep reporting periods/currency/scale separate and verify interval-specific history availability. For commercial use, choose a licensed feed when the workflow needs redistribution rights, exchange entitlements or service-level commitments.
Conclusion
Use yfinance for structured historical downloads and a contract-driven HTML parser for permitted page-specific data. The important result is not merely a file: it is a correctly identified, consistently adjusted dataset with traceable dates, units and failure records.
Start with one ticker and one short window. Validate the output, cache completed work and expand only when the collection route and data rights support the job. Where an authorized workflow needs residential routing, configure a traffic-capped Socks5.IO sub-account and choose the appropriate session mode. Keep that network decision separate from the source’s data quality and usage terms.











