Python ve Node.js'te proxy nasıl kullanılır
requests, httpx, aiohttp, Node.js fetch ve axios için kod örnekleri — HTTP ve SOCKS5, kimlik doğrulama ve IP rotasyonu ile.
Kazıyıcı, bot veya otomasyon yazıyorsanız proxy eklemek birkaç satır sürer. host:port:login:password biçimindeki bilgiler «Proxy'lerim»dedir.
Python: requests
import requests
proxy = "http://login:password@host:port"
r = requests.get("https://ipinfo.io/json", proxies={"http": proxy, "https": proxy}, timeout=30)
print(r.json()["ip"])
SOCKS5 için: pip install requests[socks] ve socks5h:// şeması.
Python: httpx ve aiohttp
import httpx
async with httpx.AsyncClient(proxy="http://login:password@host:port", timeout=30) as client:
r = await client.get("https://ipinfo.io/json")
import aiohttp
async with aiohttp.ClientSession() as s:
async with s.get("https://ipinfo.io/json", proxy="http://login:password@host:port") as r:
print(await r.json())
Node.js: undici / fetch
import { ProxyAgent, fetch } from 'undici';
const agent = new ProxyAgent('http://login:password@host:port');
const res = await fetch('https://ipinfo.io/json', { dispatcher: agent });
Node.js: axios
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';
const agent = new HttpsProxyAgent('http://login:password@host:port');
const { data } = await axios.get('https://ipinfo.io/json', { httpsAgent: agent, proxy: false });
Node.js'te SOCKS5 için socks-proxy-agent paketi.
IP rotasyonu
Özel proxy'ler: listeden rastgele veya sırayla seçin. Mesken ve mobil: IP kendiliğinden değişir; sabit tutmak için login-session-ab12cd-time-10 (ayrıntılar).
Proxy'leri koddan ProxyZen API ile alın ve uzatın.
Sık hatalar
- 407 — yanlış kimlik bilgileri.
- Zaman aşımı — yanlış port; mesken ve mobil: HTTP 8080, SOCKS5 1080.
- SSL hataları — genellikle yanlış şema (HTTPS siteler için bile HTTP proxy'de
http://).
ProxyZen’i deneyin
IPv4 ve IPv6 $0.05’ten başlayan fiyatlarla, mesken ve mobil GB başına. Anında teslim, HTTP(S) ve SOCKS5.