nodejs使用爬虫代理的方案
2019-03-05 17:41
134 查看
const http = require(“http”);
const url = require(“url”);
// 要访问的目标页面 const targetUrl = "http://httpbin.org/ip"; const urlParsed = url.parse(targetUrl); // 代理服务器 const proxyHost = "t.16yun.cn"; const proxyPort = "36600"; // 生成一个随机 proxy tunnel var seed = 1; function random() { var x = Math.sin(seed++) * 10000; return x - Math.floor(x); } const tunnel = random()*100; // 代理验证信息 const proxyUser = "username"; const proxyPass = "password"; const base64 = new Buffer.from(proxyUser + ":" + proxyPass).toString("base64"); const options = { host: proxyHost, port: proxyPort, path: targetUrl, method: "GET", headers: { "Host": urlParsed.hostname, "Proxy-Tunnel": tunnel, "Proxy-Authorization" : "Basic " + base64 } }; http.request(options, function (res) { console.log("got response: " + res.statusCode); res.pipe(process.stdout); }).on("error", function (err) { console.log(err); }).end();
相关文章推荐
- 浅析分布式爬虫使用代理IP的几种方案
- 网络爬虫,使用NodeJs抓取RSS新闻
- 如何使用http/https代理ip 纯手工浏览器(ie 360 谷歌 遨游等等)使用代理Ip 爬虫(python java)如何使用代理ip 附加免费代理ip池
- nodejs之nightmare的使用--网络爬虫---论坛灌水
- crawler_爬虫代理方案
- 一次使用NodeJS实现网页爬虫记 - huan&ping - 博客园
- 爬虫(14):使用IP代理
- [python]新手写爬虫v2.5(使用代理的异步爬虫)
- 使用代理的爬虫小程序
- [Python爬虫] 使用urllib2库检测代理ip是否可用,并使用代理提交GET、POST请求
- Python 爬虫入门—— IP代理使用
- Jsoup使用代理ip爬虫
- 数据抓取之反爬虫规则:使用代理和http头信息
- Python3 爬虫中代理的使用方法
- 鱼c笔记——Python爬虫(三):使用User Agent和代理IP隐藏身份
- 使用nodejs写一个简易的爬虫
- python3实现网络爬虫(7)-- 使用ip代理抓取网页
- python selenium 爬虫,使用代理 ,和 python 爬取代理网站,保存ip
- 史上最详细nodejs版本管理器nvm的安装与使用(附注意事项和优化方案)
- Spring Boot + Java爬虫 + 部署到Linux (三、Java爬虫使用代理,模拟登录,保存cookie)