chapter無法使用find方法篩選strong標簽取不到text的值,請大神指點
var?http?=?require('http') var?cheerio?=?require('cheerio') var?url?=?'http://www.xianlaiwan.cn/learn/348' function?fliter(html){ var?$?=?cheerio.load(html) var?chapters?=?$('.chapter') console(chapters[0].find('strong').text()) } http.get(url,function(res){ var?html?=?''? res.on('data',function(data){ html?+=data }) res.on('end',function(){ fliter(html) }) }).on('error',function(){ console.log('錯誤!!!') })
報錯如下:
2016-04-21
chapters[0]改為chapters.eq(0)