快捷导航

请大神帮忙看一下哪里问了问题?

代码如下: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("数据抓取失败~");});一直报错..............

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员2


命名重复,导致chapter数组被覆盖
回复

使用道具 举报

非常感谢~~我真是太粗心了
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP