5 分钟完成代理 IP API 集成:Python 与 Node.js 实战教程
Rola IP 提供标准 HTTP 代理协议,兼容所有支持代理配置的编程语言和工具。本文演示如何在 Python 和 Node.js 中快速集成住宅代理,从注册到发出第一个请求不超过 5 分钟。
第一步:获取代理凭证
登录 Rola IP 控制台,在「代理设置」页面获取您的代理地址、端口、用户名和密码。代理地址格式为 pr.rola-ip.co,端口 7777(HTTP)或 SOCKS5 协议。
Python 集成示例
使用 requests 库,只需设置 proxies 参数即可。通过用户名参数控制代理 IP的国家和会话模式,例如 customer-USER-country-us-session-rand123 表示美国 IP 且保持粘性会话。
import requests
username = "customer-USER"
password = "PASS"
proxy = "pr.rola-ip.co:7777"
proxies = {
"http": f"http://{username}:{password}@{proxy}",
"https": f"http://{username}:{password}@{proxy}",
}
response = requests.get("https://ip.rola-ip.co/location", proxies=proxies)
print(response.text)
Node.js 集成示例
使用 axios 配合 https-proxy-agent,同样通过代理 URL 中的用户名参数实现国家定位和会话控制。对于 Puppeteer 和 Playwright,在 launch 参数中设置 --proxy-server 即可让所有浏览器流量走住宅代理。
import fetch from "node-fetch";
import { HttpsProxyAgent } from "https-proxy-agent";
const username = "customer-USER";
const password = "PASS";
const proxy = "pr.rola-ip.co:7777";
const agent = new HttpsProxyAgent(`http://${username}:${password}@${proxy}`);
const response = await fetch("https://ip.rola-ip.co/location", { agent });
console.log(await response.text());
高级参数说明
用户名格式支持以下参数:country-XX 指定国家(如 country-us);state-XX 指定州/省;city-XX 指定城市;session-XXX 设置粘性会话 ID(相同 ID 保持同一 IP)。完整 API 文档和 SDK 请访问控制台文档中心。






