从网站节点js抓取数据

时间:2018-03-25 18:01:33

标签: node.js web-scraping request cheerio

我是从网站上抓取数据的新手,我想从以下地方抓取级别编号:https://fortnitetracker.com/profile/pc/Twitch.BadGuyBen,我尝试过使用cheerio并请求此任务,我不确定我是否使用正确的选择器关于我应该做什么的一些提示。这是我的代码:

var request = require('request');
var cheerio = require('cheerio');

var options = {
    url: `https://fortnitetracker.com/profile/pc/Twitch.BadGuyBen`,
    method: 'GET'
}

request(options, function (error, response, body) {    
    var $ = cheerio.load(body);

    var level = "";
    var xp = "";

    $('.top-stats').filter(function(){

        var data = $(this);
        level = data.children().first().find('.value').text();

        console.log(level);
    })
});

我不确定我是否选择了非常受欢迎的合适课程。

编辑:

还有'.top-stats'进一步出现在

website open in chrome dev tools

other .top-stats class

1 个答案:

答案 0 :(得分:0)

You can't use request to get the body since the stats are displayed using javascript. You will have to use something like puppeteer to request the page and execute the javascript and then scrape the stats.