Implementation:AI4Finance Foundation FinGPT Proxy Header Rotation
| Knowledge Sources | |
|---|---|
| Domains | Web_Scraping, Proxy_Management, RAG |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete tool for rotating user-agent headers and fetching free proxies to evade anti-bot detection during web scraping provided by the FinGPT RAG multisource_retrieval subproject.
Description
The headers module maintains a pool of ~20 user-agent strings (Chrome, Firefox, IE/Trident) and provides `getFreeProxies` to scrape free-proxy-list.net, `getProxy` to return a working proxy, and `getHeaders` to return rotated headers for a given site (Seeking Alpha, NASDAQ).
Usage
Import these functions when you need to make HTTP requests to financial news sites while evading simple anti-bot measures.
Code Reference
Source Location
- Repository: AI4Finance_Foundation_FinGPT
- File: fingpt/FinGPT_RAG/multisource_retrieval/proxies/headers.py
- Lines: 1-159
Signature
class Site(Enum):
SA = 1
NASDAQ = 2
def getFreeProxies() -> list[str]:
"""Scrape free-proxy-list.net and return proxy URLs."""
def getProxy() -> str | None:
"""Return a working proxy from the free list."""
def getHeaders(site) -> dict:
"""Return rotated headers for a given Site enum value."""
Import
from proxies.headers import getProxy, getHeaders, Site
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| site | Site | Yes (getHeaders) | Target site enum (SA, NASDAQ) |
Outputs
| Name | Type | Description |
|---|---|---|
| proxy | None | Working proxy URL or None |
| headers | dict | HTTP headers with rotated User-Agent |
Usage Examples
Make a Rotated Request
import requests
from proxies.headers import getHeaders, getProxy, Site
headers = getHeaders(Site.SA)
proxy = getProxy()
proxies = {"http": proxy, "https": proxy} if proxy else None
response = requests.get("https://seekingalpha.com/symbol/AAPL",
headers=headers, proxies=proxies)
print(response.status_code)