我一直在尝试为我们正在构建的网站抓取 10 个网站,其中包含指向原始网站的链接,在 node.js 上使用cheerio,我们得到的问题是一些网站已经改变,现在使用 ajax 调用来带来他们的数据,我的问题是我们如何获取这些信息,例如先触发按钮单击然后获取 DOM。
其次:相同的 dom 结构并没有获取我所有的数据,它正在检索一个页面的信息,但没有获取具有相同 DOM 结构的另一页面上的元素。任何帮助,将不胜感激。
谢谢并恭祝安康。 编辑1:相关代码
$('#ProductContent').filter(function(){ var price = undefined; var ukulele = false; var model = $(this).find('.ProductSubtitle').text().replace(/\n\s*/g,""); if(model.indexOf(/m/i) != 0){ var description = $(this).find('.RomanceCopy').text().replace(/\n\s*|\r/g,""); . .code removed for brevity and the variables present here are populated . //this children is populated only for one page. children = $(this).find('.SpecsColumn .SpecsTable table tbody').children('tr'); console.log('children: '+children.length) console.log(guitar_url); children.each(function(){ var key = $(this).children('td').first().text(); var value = $(this).children('td').last().text(); specs[key] = value; console.log(specs); });
编辑 2: Cherios 初始化
request(guitar_url,function(error,response,html){ if(!error){ var $ = cheerio.load(html); $("#content #right-content").filter(function(){..children and other variables are populated inside here....}) } })