代碼如下:var http = require("http");var url = "http://www.zhiread.com/";var cheerio = require("cheerio");//獲取章節(jié)數(shù)據(jù)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;?}// 打印章節(jié)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("數(shù)據(jù)抓取失敗~");});一直報錯..............
- 3 回答
- 0 關(guān)注
- 1196 瀏覽
添加回答
舉報
0/150
提交
取消