Integracja z Python Requests i curl_cffi
Dowiedz się, jak kierować scrapery oparte na Python Requests i curl_cffi z podszywaniem się pod TLS przez mobilne proxy XProxy 4G/5G z automatycznym wyzwalaniem rotacji adresów IP przy limitach szybkości HTTP 429/403.
Dlaczego warto używać XProxy z Python Requests i curl_cffi?
Python Requests oraz curl_cffi (które na poziomie gniazd naśladują odciski palca TLS przeglądarek Chrome/Firefox) to najpopularniejsze biblioteki do szybkiego i lekkiego scrapingu stron internetowych. Kierowanie skryptów Pythona przez hostowane samodzielnie mobilne proxy XProxy 4G/5G pozwala ominąć odcisk palca TLS Cloudflare oraz limity szybkości IP przy nieograniczonej przepustowości danych.
Wymagania wstępne
- Python 3.8+ z zainstalowanymi bibliotekami
requestsicurl_cffi(pip install requests curl_cffi). - Działający serwer XProxy z aktywnymi modemami USB 4G/5G lub telefonami z systemem Android.
- Dane uwierzytelniające proxy (IP, Port, Nazwa użytkownika, Hasło, Link API rotacji) z panelu XProxy.
1. Standardowy przykład z Python Requests
Poniżej znajduje się kompletny skrypt demonstrujący automatyczną rotację adresów IP XProxy po otrzymaniu kodów statusu HTTP 429 lub 403:
import time
import requests
# --- XProxy Configuration ---
PROXIES = {
"http": "http://username:[email protected]:5001",
"https": "http://username:[email protected]:5001",
}
ROTATION_API_URL = "http://192.168.6.7:8081/api/v1/rotate_ip/position/1"
def rotate_xproxy_ip():
"""Trigger 4G/5G cellular reconnection on XProxy."""
print("🔄 Triggering XProxy IP rotation...")
try:
res = requests.get(ROTATION_API_URL, timeout=10)
if res.status_code == 200:
print("✅ IP rotation requested. Waiting 6 seconds for 4G reconnect...")
time.sleep(6)
return True
except Exception as e:
print(f"❌ Rotation error: {e}")
return False
def scrape_url(url):
for attempt in range(3):
try:
response = requests.get(url, proxies=PROXIES, timeout=15)
# Handle rate limits or anti-bot blocks
if response.status_code in (429, 403):
print(f"⚠️ Encountered HTTP {response.status_code}. Rotating IP...")
rotate_xproxy_ip()
continue
print(f"✅ Success ({response.status_code}): {response.text[:100]}")
return response
except requests.exceptions.RequestException as e:
print(f"❌ Request error: {e}. Retrying with new IP...")
rotate_xproxy_ip()
if __name__ == "__main__":
scrape_url("https://api.ipify.org?format=json")2. Podszywanie się pod TLS za pomocą `curl_cffi`
Aby ominąć kontrolę odcisków palca TLS Cloudflare i Akamai podczas korzystania z mobilnych adresów IP XProxy 4G/5G, użyj curl_cffi do podrobienia prawdziwych sygnatur TLS przeglądarki Chrome:
from curl_cffi import requests
# Configure SOCKS5 or HTTP proxy with Chrome TLS impersonation
proxy_url = "socks5://username:[email protected]:5001"
response = requests.get(
"https://tls.browserleaks.com/json",
proxies={"http": proxy_url, "https": proxy_url},
impersonate="chrome120", # Impersonate Chrome 120 TLS fingerprint
timeout=15
)
print("Status Code:", response.status_code)
print("TLS Response:", response.json())Często zadawane pytania
- P: Czy z Python Requests powinienem używać HTTP czy SOCKS5?
O: Standardowa bibliotekarequestsświetnie współpracuje z proxy HTTP. Aby uzyskać obsługę SOCKS5 w Python Requests, zainstalujrequests[socks](np.socks5h://user:[email protected]:5001).
Why High-Quality SOCKS5 UDP & Mobile Proxies Matter for Python Requests & Scrapers
Using cheap datacenter proxies or basic HTTP proxies in antidetect profiles leads to instant account suspensions on Facebook, Google, TikTok, and Amazon. Here is why XProxy's self-hosted 4G/5G mobile proxies deliver superior anonymity and trust:
- SOCKS5 with Full UDP Support: Unlike standard HTTP proxies that drop UDP packets, XProxy SOCKS5 proxies fully support UDP datagrams. This ensures WebRTC, DNS queries, and real-time audio/video sockets route securely through your proxy without revealing your real IP address.
- Instant REST API IP Rotation: Trigger cellular IP rotation on demand via simple HTTP GET requests (e.g.
http://192.168.6.7:8081/api/v1/rotate_ip/position/1). Reconnect 4G/5G USB modems in 3 to 8 seconds with zero proxy dropouts. - 100% WebRTC & DNS Leak Protection: Combined with XProxy's local LAN gateway and TCP OS Spoofing, your browser profiles maintain pristine anonymity scores on BrowserLeaks, Whoer, Pixelscan, and IPhey.
- Carrier-Grade NAT (CGNAT) Trust: Mobile carrier IPs are shared by thousands of active smartphone users. Major platforms never ban mobile IP ranges, granting your accounts maximum trust.
