首页 > Web开发 > 详细

nodejs利用superagent爬取数据的简单例子

时间:2017-01-24 09:59:53      阅读:437      评论:0      收藏:0      [点我收藏+]

爬取世界银行统计数据

安装:npm install superagent

技术分享
/**
 * Created by zh on 16-9-7.
 */
var request = require(‘superagent‘)
    , fs = require(‘fs‘);
var xlsx = require("node-xlsx");

function sleep(milliSeconds) {
    var startTime = new Date().getTime();
    while (new Date().getTime() < startTime + milliSeconds);
}

var list = xlsx.parse("/home/zh/桌面/API_BTN_DS2_zh_excel_v2.xlsx");
list[2][‘data‘].forEach(function(row){
    url=‘http://api.worldbank.org/v2/zh/indicator/‘+row[0]+‘?downloadformat=excel‘;
    console.log(row[1],url);
    //console.log();
    sleep(5000);
    var stream = fs.createWriteStream(‘/home/zh/project/cloudmap/worldbank/‘+row[1]+‘.xls‘);
    var req = request.get(url);
    req.pipe(stream);
    sleep(5000);
});
View Code

附件:API_BTN_DS2_zh_excel_v2.xlsx

nodejs利用superagent爬取数据的简单例子

原文:http://www.cnblogs.com/Micang/p/6346474.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!