在 Node.js 中配置代理 IP 采集文章

慈云数据 2024-04-23 技术支持 102 0

不说废话,直接上代码:

const http = require('http');
const https = require('https');
// 之后可以使用 http 或 https 模块发起请求,它们将自动使用配置代理
// 代理ip:https://www.kuaidaili.com/?ref=rg3jlsko0ymg
const proxy = 'http://代理IP:端口';
http.globalAgent = new http.Agent({
  proxy: proxy,
});
https.globalAgent = new https.Agent({
  proxy: proxy,
});

代理ip这里有:https://www.kuaidaili.com/?ref=rg3jlsko0ymg

这只是一个简单的案例也是核心,业务需求自行扩展

微信扫一扫加客服

微信扫一扫加客服

点击启动AI问答
Draggable Icon