代码如下:
var http = require("http");
var url = "http://www.zhiread.com/";
var cheerio = require("cheerio");
//获取章节数据
function getChpater(html)
{
var $ = cheerio.load(html);
var chapterData = $(".selection-courier-content ul").children("li");
var chapter=[];
chapterData.each(function(item){
var chapter = $(this);
var title = chapter.find("h4").text();
var autor = chapter.find("span").text();
var img = chapter.find("img").attr("src");
var chapterItem = {
title:title,
autor:autor,
img:img
};
chapter.push(chapterItem);
});
return chapter;
}
// 打印章节
function printChpater(chapter)
{
chapter.forEach(function(item){
console.log("title:"+item.title+" autor:"+item.autor+" img:"+item.img+"/n");
});
}
http.get(url,function(res){
var html = "";
res.on("data",function(data){
html += data;
});
res.on("end",function(){
var chapter = getChpater(html);
printChpater(chapter);
});
}).on("error",function(){
console.log("数据抓取失败~");
});
一直报错..............
堂堂堂堂糖糖糖童鞋
lala_over
相关分类