为何选择 NODE.JS + PROXY POLAND
Node.js 是服务器端自动化、API 爬取和无头浏览器自动化的首选运行时。通过 Proxy Poland 的 4G/5G 手机代理路由您的 Node.js 请求,您将获得真实的手机运营商 IP,可绕过反机器人系统和地理限制。
Node.js 配置应使用生产环境相同的代理协议、浏览器配置、目标网站和账号流程来测试。扩展前请检查可见 IP、DNS 路由、ASN、会话保持、轮换行为、登录状态、HTTP、SOCKS5、OpenVPN、VLESS 和控制台状态是否一致。
这页是中文集成指南,说明如何把移动代理接入浏览器、脚本、反检测工具或自动化框架。重点检查代理主机、端口、协议、认证、DNS 路由、出口 IP、会话保持和轮换行为是否与工具设置一致。
完成配置后不要直接扩大任务量。先用小流量验证目标网站响应、账号登录状态、浏览器指纹、地理位置、运营商网络、超时、重试和错误码,再决定是否进入生产工作流。
设置说明
- 01
安装 HTTP 客户端库
安装 axios 或使用内置 https 模块:
npm install axios # For SOCKS5 support: npm install socks-proxy-agent # For HTTPS proxy: npm install https-proxy-agent
- 02
获取代理凭据
在 proxypoland.com 注册并获取您的代理 IP、端口、用户名和密码。
- 03
使用 Axios 配置 HTTP 代理
通过代理路由 Axios 请求:
const axios = require('axios'); const response = await axios.get('https://httpbin.org/ip', { proxy: { host: 'proxy-ip', port: 8080, auth: { username: 'your-username', password: 'your-password', }, protocol: 'http', }, }); console.log(response.data); // Should show Polish mobile IP - 04
使用原生 https 模块配置
使用 Node.js 内置 https 带 SOCKS5 代理:
const { SocksProxyAgent } = require('socks-proxy-agent'); const https = require('https'); const agent = new SocksProxyAgent( 'socks5://username:password@proxy-ip:port' ); const options = { hostname: 'httpbin.org', path: '/ip', agent, }; https.get(options, (res) => { let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => console.log(JSON.parse(data))); }); - 05
与 node-fetch 一起使用
配置带代理代理的 node-fetch:
const fetch = require('node-fetch'); const { HttpsProxyAgent } = require('https-proxy-agent'); const agent = new HttpsProxyAgent( 'http://username:password@proxy-ip:port' ); const response = await fetch('https://httpbin.org/ip', { agent }); const data = await response.json(); console.log(data); - 06
添加 IP 轮换
使用轮换 API 在爬取会话之间轮换 IP:
const axios = require('axios'); async function rotateIP() { const response = await axios.get( `http://proxy-ip:port/rotate`, { auth: { username: 'user', password: 'pass' } } ); console.log('New IP:', response.data); return response.data; } // Rotate between scraping tasks await rotateIP(); const result = await axios.get('https://target-site.com', { proxy: proxyConfig }); - 07
验证您的 IP
检查您的请求是否通过代理路由:
const axios = require('axios'); const response = await axios.get('https://httpbin.org/ip', { proxy: { host: 'proxy-ip', port: 8080, auth: { username: 'user', password: 'pass' }, }, }); console.log(response.data.origin); // Should show Polish mobile carrier IP
专业提示
使用 https-proxy-agent 或 socks-proxy-agent 与大多数 Node.js HTTP 客户端兼容
使用 p-retry 或指数退避实施重试逻辑以进行弹性爬取
使用 async/await 和 Promise.all 进行并发代理路由请求
在爬取批次之间轮换 IP 以避免基于 IP 的封禁
使用 user-agents npm 包设置真实的 User-Agent 标头
适用于以下场景
FAQ
哪个 Node.js HTTP 库最适合手机代理?+
Axios 因其简单的代理配置而最受欢迎。对于原生使用,https-proxy-agent 和 socks-proxy-agent 与 Node.js 内置模块配合使用。got 和 node-fetch 也支持代理代理。
如何在 Node.js 中使用 SOCKS5 代理?+
安装 socks-proxy-agent(npm install socks-proxy-agent),并将其作为代理参数传递给您的 HTTP 客户端。代理 URL 格式为:socks5://用户:密码@主机:端口。
如何在 Node.js 中处理代理认证?+
对于 Axios,使用 auth.username 和 auth.password 设置代理配置对象。对于基于代理的客户端,在代理 URL 中包含凭据:http://用户名:密码@主机:端口。
我可以在 Node.js 中将这些代理与 Playwright 或 Puppeteer 一起使用吗?+
可以。将 --proxy-server=socks5://主机:端口 作为启动参数传递。然后使用 page.authenticate() 提供凭据。请参阅我们专用的 Puppeteer 集成指南。
如何在 Node.js 中实施 IP 轮换?+
在爬取任务之间调用轮换端点(在您的代理上 GET /rotate)。API 返回新的 IP 地址。您可以使用简单的 setInterval 或按请求触发来自动化此过程。
如何在Node.js中使用HttpsProxyAgent与Proxy Poland?+
const {HttpsProxyAgent} = require('https-proxy-agent'); const agent = new HttpsProxyAgent('http://user:pass@host:port'); fetch(url, {agent})或axios.get(url, {httpsAgent: agent})。对于SOCKS5:const {SocksProxyAgent} = require('socks-proxy-agent'); const agent = new SocksProxyAgent('socks5://user:pass@host:port')。两个包都处理认证握手,无需手动管理407响应。
Proxy Poland的axios代理配置是什么?+
axios.get(url, {proxy: {host: 'host', port: PORT, auth: {username: 'u', password: 'p'}, protocol: 'http'}'})。注意:axios的proxy字段原生支持HTTP/HTTPS代理,但不支持SOCKS5——对于SOCKS5,使用SocksProxyAgent作为httpsAgent:axios.get(url, {httpsAgent: new SocksProxyAgent('socks5://user:pass@host:port')})。
got是否适用于Proxy Poland的SOCKS5?+
got本身不支持SOCKS5——安装socks-proxy-agent并传递:const {SocksProxyAgent} = require('socks-proxy-agent'); got(url, {agent: {https: new SocksProxyAgent('socks5://user:pass@host:port')}'})。对于HTTP代理,got原生支持:got(url, {agent: {https: new HttpsProxyAgent('http://user:pass@host:port')}'})。
如何为Proxy Poland配置undici dispatcher?+
Node 18+的undici。const {ProxyAgent, setGlobalDispatcher} = require('undici'); setGlobalDispatcher(new ProxyAgent('http://user:pass@host:port'))。设置全局dispatcher后,所有通过fetch()的请求都会通过代理路由。对于每请求代理:fetch(url, {dispatcher: new ProxyAgent('http://user:pass@host:port')})。undici的ProxyAgent不原生支持SOCKS5——对于SOCKS5,改用HttpsProxyAgent。
如何在Node.js中实现轮换代理池?+
维护const agents = proxies.map(p => new HttpsProxyAgent(p)); let i = 0; const next = () => agents[i++ % agents.length]; fetch(url, {agent: next()})。对于基于rotation API的IP轮换(而非仅仅循环端点),在fetch之间调用rotation API:await fetch(rotateUrl, {method:'POST'}); await sleep(12000); 继续用同一个agent进行下一个请求——IP在代理端点下面改变。
Node.js中的Playwright是否按浏览器上下文绑定Proxy Poland?+
是的——chromium.launch({proxy: {server: 'http://host:port', username, password}'})用于浏览器级别。browser.newContext({proxy: {server: 'http://host:port', username, password}'})用于上下文级别(推荐用于多账号,每个上下文独立的代理)。Playwright原生处理代理认证,无需proxy-chain。每个newContext调用可以指定不同的Proxy Poland端点,实现真正的每账号代理隔离。
如何从Node.js发送rotation API调用?+
fetch('https://api.proxypoland.com/rotate?token=' + TOKEN, {method: 'POST'}).then(r => r.json())。Node 18+原生fetch可用,无需导入。等待10-15秒后再继续爬取:await fetch(rotateUrl, {method:'POST'}); await new Promise(r => setTimeout(r, 12000))。要验证IP已更改,在轮换前后获取ifconfig.me并比较结果。