码迷,mamicode.com
首页 > Web开发 > 详细

nodejs抓网易NBA数据

时间:2015-01-19 18:45:48      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

var http = require("http");
var cheerio = require("cheerio");

var url = "http://nba.sports.163.com/2014/team/structure/17.html";

download(url, function(data) {
if (data) {
var $ = cheerio.load(data);
$("#team_header option").each(function(i, e){
console.log(‘team:\t‘, $(e).text());
})
console.log($(".tb-title").text());
$(".dataTB3 td a").each(function(i, e){
console.log("member:", $(e).text());
})
}
else {
console.log("error")
};
});

function download(url, callback) {
http.get(url, function(res) {
var data = "";
res.on(‘data‘, function (chunk) {
data += chunk;
});
res.on("end", function() {
callback(data);
});
}).on("error", function() {
callback(null);
});
}

 

id用"#", class用"."

参考:http://www.75team.com/archives/543

http://www.cnblogs.com/craryprimitiveman/p/3674421.html

nodejs抓网易NBA数据

标签:

原文地址:http://www.cnblogs.com/zhaoyier/p/4234289.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!