var http = require("http");
var cheerio = require("cheerio");html
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")
};
});ui
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);
});
}url
id用"#", class用"."htm
參考:http://www.75team.com/archives/543blog
http://www.cnblogs.com/craryprimitiveman/p/3674421.htmlget