Was this helpful?
How to scrape TipRanks
Technical engineer
Scraping financial data from investment platforms has its own specifics, especially when dealing with sites that employ caching layers and bot management. Unlike many other websites, an effective scraper for TipRanks should not rely on fragile CSS selectors or heavy HTML parsing.
In this guide, we will explore how to reliably and quickly extract stock forecast data using the open-source project 2scraper/tipranks-scraper, minimizing overhead and correctly handling the site architecture.
What we will build
A script capable of extracting a comprehensive stock ticker forecast snapshot from free, unauthenticated public pages. No account or login is required for a normal run.
Extracted data per ticker includes:
- Core metrics: smart_score, consensus_rating_label (Buy/Hold/Sell), analyst_count, buy_count, hold_count, sell_count.
- Price targets: price_target_average, price_target_high, price_target_low, price_target_upside.
- Best performing analysts: a separate subset of the above metrics prefixed with best_.
- Company info: company_name, currency, current_price, current_price_asof, source_url, scraped_at.
- Advanced fundamentals (added in v0.6.0): dividend details (yield, payout ratio, next ex-date), earnings dates and estimates, insider sentiment and net USD, hedge fund sentiment and net shares, retail investor sentiment, news sentiment and bullish ratio, and blogger opinion counts.
Important: the scraper reads data directly from the internal JSON payload endpoint, not by parsing the rendered HTML. This makes it highly resilient to UI changes.
Requirements
- Python: version 3.9 or newer.
- Browser engine: playwright (chromium) is the primary and recommended option. Selenium and puppeteer (pyppeteer) are also supported for compatibility.
- Environment: it is recommended to use a separate virtual environment for each engine, as their dependencies may conflict.
- Optional: proxy configuration or 2Captcha Scraper API key for handling strict Cloudflare challenges, though a local run works perfectly for most use cases.
Project setup
-
Clone the repository and create a virtual environment:
bashgit clone https://github.com/2scraper/tipranks-scraper.git cd tipranks-scraper python3 -m venv .venv source .venv/bin/activate # For Windows: .venv\Scripts\activate -
Install dependencies for the chosen engine. Do not install multiple engines in one environment:
bash# Primary option (recommended) pip install -r requirements-playwright.txt playwright install chromium # Alternative options (only if necessary) # pip install -r requirements-selenium.txt # pip install -r requirements-puppeteer.txt -
Copy the environment configuration file:
bashcp .env.example .envLeave it empty for a local run without proxies or API keys.
Quick start
The main entry points are the engine-specific scripts. Here are launch examples for different scenarios:
bash
# 1. Scrape a single ticker and save to json
python3 playwright_scraper.py --ticker AAPL --format json --out results.json
# 2. Scrape multiple tickers in one run
python3 playwright_scraper.py --ticker AAPL --ticker MSFT --ticker TSLA --format csv --out stocks.csv
# 3. Scrape from a text file (one ticker per line, supports comments)
python3 playwright_scraper.py --tickers-file watchlist.txt --format json --out results.json
# 4. Run with a visible browser for debugging purposes
python3 playwright_scraper.py --ticker NVDA --headed
Note on performance: the scraper navigates directly to the internal payload.json endpoint for each ticker, bypassing the main HTML page entirely. This avoids unnecessary rendering and significantly speeds up execution.
How the scraper works
The project architecture is designed for maximum reliability and minimal friction:
- Direct JSON access: the URL
https://www.tipranks.com/stocks/{ticker}/stock-analysis/payload.jsonis fetched directly. No CSS selectors or DOM scraping are used for any field. - Edge caching awareness: the site uses Fastly for caching (up to 5 minutes for the payload) and Cloudflare for bot management. The scraper is designed to work seamlessly within these constraints.
- Block avoidance: live testing confirmed that while the main HTML page sometimes triggers a Cloudflare challenge, the payload.json endpoint remains accessible from standard residential or datacenter IPs without triggering blocks.
Data extraction
1. Core analyst data
The scraper extracts the exact 1-10 smart score, the human-readable consensus label (e.g., Moderate Buy), and the precise breakdown of analyst ratings. Price target upside is provided as a fraction (e.g., -0.018 for -1.8 percent).
2. Fundamental expansions
Starting from version 0.6.0, the tool also captures dividends, upcoming earnings dates, insider trading sentiment, hedge fund activity, retail investor trends, news sentiment, and blogger opinions. All sentiment values use the site's native identifiers (veryNegative, negative, neutral, positive, veryPositive).
3. Output contract
Each result row is strictly typed. Missing data (e.g., a company with no dividend history or no analyst coverage) is represented as null, reflecting the actual state of the source payload rather than forcing default values.
Working with engines and proxies
The project supports three engines but has strict technical limitations that are important to know:
| Engine | Features | Limitations |
|---|---|---|
| playwright | Primary and recommended option. Supports authenticated remote CDP endpoints and advanced captcha auto-solving. | No significant limitations. |
| selenium | Alternative option for specific environments. | Does not support authenticated remote CDP endpoints or proxies with username and password. |
| puppeteer (pyppeteer) | Provided for compatibility only. | Effectively unmaintained. May require manual executable path configuration on Apple Silicon. |
Important proxy details:
- The scraper uses one proxy for the entire run and does not rotate per ticker, as sequential JSON fetches do not generate enough volume to trigger rotation-based blocks.
- If a proxy is completely dead, the browser is relaunched with the next proxy in the list, and the failed ticker is retried automatically.
Advanced techniques and debugging
For stable operation in automated mode, the scraper provides several powerful flags:
- --headed: launches a visible browser window instead of headless mode, invaluable for visual debugging of network requests.
- --allow-empty: by default, if every requested ticker returns no data, the scraper protects your previous results by not overwriting the output file. This flag disables that protection if you explicitly need an empty state.
- --block-retries: on a blocked outcome, retries that specific ticker on the same browser session a specified number of extra times before giving up, maximizing the chance of success without rotating infrastructure.
Integration into automation: exit codes
Understanding exit codes is critical for configuring cron jobs or CI/CD pipelines. The scraper always returns a clear status:
| Code | Meaning | Action for automation |
|---|---|---|
0 |
Complete | Data collected successfully, file updated. |
2 |
Bad usage | Check arguments. For example, no tickers were provided or an invalid flag was used. |
3 |
Blocked | A real 403/429 or Cloudflare interstitial was detected. Consider using a proxy or CDP endpoint. |
4 |
Zero results | Every ticker answered not found (confirmed 404/400 from the site). |
5 |
No rows obtained | Navigation or network failure, or a served payload the parser could not read. |
6 |
Partial | Some tickers failed, but others succeeded. Check the meta.json sidecar for details. |
Every successful or partial run creates a sidecar file named with a .meta.json extension, containing metadata such as status, stop reason, and a count of escaped CSV cells.
Scaling and limitations
- No rate limiting observed: testing showed that fetching the entire S&P 500 (over 500 tickers) sequentially from a single IP completes in under three minutes without triggering 403 or 429 errors.
- Forecast page only: the tool is specifically designed for the stock-analysis forecast page. It does not scrape stock screeners, options chains, or detailed per-transaction insider lists.
- Not real-time quotes: the current_price field reflects the last trading day's close as provided in the payload, not a live market feed.
Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
ModuleNotFoundError on launch |
Attempting to use an engine without installing its dependencies | Install the specific requirements file in a clean virtual environment. |
| Exit code 3 (blocked) | Cloudflare challenged the request | Switch to a residential proxy via --proxy or use the 2Captcha Scraper API via --scraper-api. |
Exit code 2 with --cdp-endpoint in selenium |
Selenium does not support authenticated WebSocket connections | Switch to the playwright engine to work with remote CDP endpoints. |
| Dependency conflict on Apple Silicon | Pyppeteer bundled chromium segfaults | Use playwright instead, or provide a local Chrome installation path via --executable-path. |
Example output
A fragment of real output in JSON format (data obtained during live testing):
json
{
"ticker": "AAPL",
"company_name": "Apple Inc.",
"smart_score": 8,
"smart_score_updated": "2026-10-19T12:00:00Z",
"consensus_rating_id": "moderateBuy",
"consensus_rating_label": "Moderate Buy",
"analyst_count": 45,
"buy_count": 28,
"hold_count": 15,
"sell_count": 2,
"price_target_average": 245.50,
"price_target_high": 300.00,
"price_target_low": 180.00,
"price_target_upside": 0.085,
"current_price": 226.25,
"current_price_asof": "2026-10-18T20:00:00Z",
"currency": "USD",
"dividend_yield": 0.0045,
"next_earnings_date": "2026-11-02",
"insider_sentiment": "neutral",
"hedge_fund_sentiment": "positive",
"news_sentiment": "positive",
"source_url": "https://www.tipranks.com/stocks/AAPL/stock-analysis",
"scraped_at": "2026-10-20T10:15:30Z"
}
Example of programmatic processing
Since the scraper outputs structured JSON, it is easy to integrate into financial analysis pipelines. Below is an example script that reads the results and filters for stocks with a high smart score and positive news sentiment:
python
import json
from pathlib import Path
def analyze_high_potential_stocks(json_file: str):
path = Path(json_file)
if not path.exists():
print(f"File {json_file} not found.")
return
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
# Filter for strong fundamentals
strong_stocks = [
item for item in data
if item.get("smart_score", 0) >= 8
and item.get("news_sentiment") in ["positive", "veryPositive"]
and item.get("price_target_upside", 0) > 0.05
]
if not strong_stocks:
print("No stocks matching the criteria found.")
return
# Sort by highest price target upside
strong_stocks.sort(key=lambda x: x.get("price_target_upside", 0), reverse=True)
print("\n--- High potential stocks ---")
for item in strong_stocks[:5]:
ticker = item.get("ticker", "Unknown")
name = item.get("company_name", "Unknown")
score = item.get("smart_score", 0)
upside = item.get("price_target_upside", 0) * 100
print(f"• {ticker} ({name})")
print(f" Smart Score: {score}/10 | Potential Upside: {upside:.1f}%")
print(f" News Sentiment: {item.get('news_sentiment')}\n")
if __name__ == "__main__":
analyze_high_potential_stocks("results.json")
Architectural feature: direct JSON endpoint access
A defining characteristic of this scraper is that every engine navigates straight to the payload.json endpoint, completely avoiding the main ticker HTML page. Live testing confirmed that while the main HTML page sometimes triggers a Cloudflare challenge, the payload endpoint remains accessible. This architectural choice eliminates the need for complex DOM parsing and drastically reduces the chance of being blocked by standard bot management systems.
Conclusion
Reliable scraping of financial data from TipRanks does not require complex protection bypasses or constant paid services. Understanding that the website serves its core data through a direct JSON endpoint allows for fast, stable, and highly accurate local execution using playwright.
Selenium and puppeteer engines are provided for compatibility, but playwright remains the optimal choice for production. Always check the exit codes to build reliable automation, and leverage the structured JSON output to seamlessly integrate stock forecasts into your analytical workflows.