BrowserForge
BrowserForge is a Python library designed for intelligent browser header and fingerprint generation. It mimics the frequency of different browsers, operating systems, and devices found in the wild using a Bayesian generative network, providing realistic HTTP headers for web scraping and automation. It is a re-implementation of Apify's fingerprint-suite in Python, known for its extremely fast runtime and extensive customization options. The current version is 1.2.4, and it is actively maintained.
Warnings
- deprecated Direct fingerprint injection into Playwright/Pyppeteer contexts using `browserforge.injectors` has been deprecated within the `browserforge` library itself.
- gotcha When using `Camoufox` with BrowserForge for fingerprinting, some properties from BrowserForge fingerprints might not be fully passed to Camoufox. This is attributed to an outdated underlying fingerprint dataset from Apify's `fingerprint-suite`.
- gotcha For optimal stealth and to avoid detection, ensure that generated headers are consistently rotated per request or per small batch when performing extensive web scraping. Using a single generated header set for many requests can still lead to detection.
Install
-
pip install browserforge -
pip install "browserforge[all]"
Imports
- HeaderGenerator
from browserforge.headers import HeaderGenerator
Quickstart
import requests
from browserforge.headers import HeaderGenerator
# Initialize the HeaderGenerator
generator = HeaderGenerator(
browser='chrome',
os='windows',
device='desktop'
)
# Generate a set of realistic headers
headers = generator.generate()
print("Generated Headers:")
for key, value in headers.items():
print(f" {key}: {value}")
# Example of using generated headers with the requests library
try:
response = requests.get('https://httpbin.org/headers', headers=headers, timeout=10)
response.raise_for_status() # Raise an exception for HTTP errors
print("\nResponse from httpbin.org:")
print(response.json())
except requests.exceptions.RequestException as e:
print(f"\nError making request: {e}")