因为网站没有api我想从csgo统计数据,我试图从网站上刮,我知道如何加载网站等,如打印主页,但我无法想象如何加载特定值,因为它们中的大多数具有您将在下面看到的相同名称。我试图获得win%的值和kd的值,但这两个类都被称为" stats-stat",我能做到这一点吗?
我的代码是:
var UR_L = "http://csgo.tracker.network/profile/blind_snip";
request(UR_L, function(err, resp, body){
var $ = cheerio.load(body);
console.log(body)
})
更新:我的工作代码:
var UR_L = "http://csgo.tracker.network/profile/blind_snip";
request(UR_L, function(err, resp, body){
$ = cheerio.load(body);
var ele = $('.stats-stat').eq(13).text();
ele2 = $.parseHTML(ele)[0].data;
console.log(ele2);
//0 = KD
//1 = win%
//2 = games
//3 = wins
//4 = headshots
//5 = money earned
//6 = score
//7 = kills
//8 = Deaths
//9 = MVP
//10 = time played
//11 = Rounds played
//12 = rounds won
//13 = bombs set
//14 = bombs defused
//15 = hostages rescued
})
谢谢大家
答案 0 :(得分:0)
我得到了字符串值,你可以使用正则表达式获得你需要的部分。如果你只是控制掉ele,你会看到它以/ n / n开头。还要注意我正在使用.eq并选择我想要的索引。你可以改为循环查询选择器。
request(UR_L, function(err, resp, body){
$ = cheerio.load(body);
var ele = $('.stats-stat').eq(1).text();
console.log($.parseHTML(ele)[0].data);
})