节点js cheerioparsinghtml

所以我有一个问题,我不能得到一个电影的链接,我想刮“人们也喜欢”部分,它显示你的电影是相似的。 虽然因为有一个字符部分,我不能在一些电影上得到那个页面

function findCommonMovies(movie, callback){ request('http://www.imdb.com/find?ref_=nv_sr_fn&q='+ movie +'&s=all', function (error, response, body) { if (error){ return }else{ var $ = cheerio.load(body); var title = $(".result_text").first().text().split("(")[0].split(" ").join('') var commonMovies = [] var endurl = $(".findSection .findList .findResult .result_text a").attr("href") var test request('http://www.imdb.com' + endurl, function (err, response, body) { if (err){ console.log(err) }else{ var $ = cheerio.load(body); $(".rec_page .rec_item a img").each(function(){ var title = $(this).attr("title") commonMovies.push(title) }); } callback(commonMovies) }); } }); } findCommonMovies("Lucifer", function(common){ console.log(common) }) 

将打印出一个空的数组

 findCommonMovies("Lucifer", function(common){ console.log(common) }) 

将打印出一个数组里面的数据

 findCommonMovies("Gotham", function(common){ console.log(common) }) 

路西弗

http://www.imdb.com/find?ref_=nv_sr_fn&q=Lucifer&s=all

有一个这样的名称为“tt”的标签<a name="tt"></a>您可以使用此select器来获取所需的部分标签

 var endurl = $('a[name=tt]').parent().parent().find(".findSection .findList .findResult .result_text a").attr("href");