Skip to content

Scrape Crypto Prices With Python: API or HTML?

Python can pull crypto prices either from a JSON API or from a public web page. The API route is usually shorter and more stable; scraping becomes the right tool when the data you need is not exposed by an API, when API access is rate-limited or costly, or when you need to compare several sources. This guide walks through both paths, explains why a simple scraper may return a 403 or an empty table, and shows how to extend a fetch into a polling tracker with CSV storage and an email alert.

Pick the right data path first

Before writing selectors, match your goal to the cheapest reliable route. The decision table below is a dated reference from the original publication; confirm current API terms and pricing before committing.

Fetch a live price from the CoinGecko API

The CoinGecko public API accepts a keyless request with rate limits of roughly 10–30 calls per minute per IP, varying with server load. The example below requests Bitcoin in USD. For higher limits, sign up for an API key and read the official CoinGecko API docs. CoinMarketCap offers a similar Python path.

Scrape a public price table with requests and BeautifulSoup

BitInfoCharts lists general and exchange-specific crypto prices and does not provide an API, which makes it a useful demonstration target. Install requests and BeautifulSoup4 with pip or uv, then select the price cell and split its text into key/value pairs.

Command example

pip install requests beautifulsoup4

Scrape historical Bitcoin data from CoinGecko

If you need daily historical prices that are not included in the free or basic API plan, a page scraper can be a practical one-off option. The URL carries start and end dates as query parameters. The sample below parses table rows into a CSV.

Why a scraper returns 403 or an empty table

Two failure modes look similar but need different fixes. A 403 means the site refused to serve the page, often because the request looked like a bot; changing the user agent may not help. A 200 response with no data usually means the content is JavaScript-rendered and needs a headless browser. Data-center IPs are commonly flagged, so a residential proxy is often required for cloud automation.

Fetch through a managed scraping API

A managed scraping API handles JS rendering and premium proxies in one call, so you do not have to run Playwright or source new IPs. The example below uses the {{OWNER_PUBLISHER_NAME}} Python client with a premium proxy and JS rendering disabled, then parses the same table. For harder sites, a stealth proxy is available. If the target loads prices by script, enable JS rendering; if it needs clicks or date changes, supply a custom JavaScript scenario. Credit costs vary by operation and plan; the table below is a dated reference.

Build a polling tracker with CSV storage

The tracker below calls CoinMarketCap's keyless trial pro API every minute, reads the API-supplied timestamp, and appends a line to a CSV file named by date. The timestamp comes from the service, which avoids clock-skew issues on your machine. In production, remove the infinite loop and run one iteration from a cron job or scheduler. The sample output below is a dated reference from a short run.

Add an email alert when a price crosses your threshold

Extend the tracker with a threshold and a Resend email. When the price falls below the threshold, the script sends one message and pauses for an hour to avoid a flood. For a sell alert, flip the comparison. Use the same email address you registered with Resend.

Legal and ethical checks

Scraping sits in a legal gray area. Prefer public data, avoid anything behind a login wall, check robots.txt and the target's Terms of Service, and respect rate limits. Where an API covers your use case, it is usually the cleaner route. Consult a lawyer for your specific situation.

Goal-to-approach decision table
Your GoalBest ApproachWhy
Simple live priceCoinGecko or CoinMarketCap /simple/price APIIt's Free!
Historical DataCoinGecko APIPart of free demo plan (attribution required)
Exchange-specific priceUse CCXTPython SDK available
Required data is not in any APIScrape the HTMLFallback to scraping if API unavailable
Dashboard with no endpointScrape HTML, with JS render if necessaryNo easier option available
Many sources at onceUse API where possible, scrape where necessaryNeed not scrape all the sources, just scrape ones without API

Dated reference from the original publication; confirm current API terms and pricing.

Frequently asked questions

Is the CoinGecko API still free?

As of June 2026, CoinGecko has a free keyless public API for very basic functions, rate-limited by IP address. There is also a free demo plan that does not give you a commercial license and requires attribution when its data is displayed.

Can I scrape CoinMarketCap with Python?

Yes, the public pages are reachable with Python. Keep the work on public pages only; anything behind a login wall is off-limits. Two obstacles are common on those pages: prices injected by JavaScript, and bot defenses that reject automated requests. Either handle both yourself, route the fetch through a scraping API that does, or skip scraping entirely and use the CoinMarketCap API when it covers your needs.

Why does my crypto scraper return empty data?

An empty result usually has one of two causes. The site may have treated your request as a bot and refused to serve content, or the numbers you want are drawn in by JavaScript after the initial HTML arrives, so a plain HTTP fetch never sees them. A headless browser solves the second case; a proxy or managed fetch solves the first.

How do I get real-time crypto prices in Python?

Crypto price APIs usually provide up to 1-minute fresh crypto prices. Anything with lower latency would require higher-tier subscriptions with these APIs. CoinGecko, for instance, gives you the freshest prices starting only from their $100+/month Analyst plan. Scraping is also an option but there is some latency involved in fetching and parsing. The high-tier APIs can give you data through websockets for very low latency.

Do I need a proxy to scrape crypto prices?

It depends on the target. Sites without bot defenses will answer any IP, so no proxy is needed. Sites that screen out suspicious addresses, such as those tied to data centers, will reject you until the request arrives from a different IP, which is where a proxy comes in.

Is scraping crypto prices legal?

The legality of scraping is generally unsettled. Publicly available price information is the safer ground; content behind a login is where trouble tends to start. Reach for an API whenever one exists, and get a lawyer's view on your specific use case rather than relying on general guidance.

{
  "1 BTC": "62,810.09 USD",
  "coinbase": "62,657.31 USD",
  "kraken": "62,589.3 USD",
  "bitfinex": "62,626 USD",
  "bitstamp": "62,670.37 USD",
  "okex": "62,723.5 USD",
  "1 USD": "0.000016 BTC"
}
Managed fetch credit-cost reference
OperationCredit Cost
Classic Scrape Without JS1
Classic Scrape With JS Render5
Premium Proxy Without JS10
Premium Proxy With JS Render25
Stealth Proxy (Forces JS)75

Dated reference; credit costs vary with subscription plans.