不说废话,直接上代码:
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