标签:
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
标签:
原文地址:http://www.cnblogs.com/zhaoyier/p/4234289.html