html 抓取,获取同名的不同值
html scraping, getting different values with the same name
因为没有 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
})
谢谢大家
我得到了字符串值,您可以使用正则表达式来获取您需要的部分。如果你只是控制台输出 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);
})
因为没有 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
})
谢谢大家
我得到了字符串值,您可以使用正则表达式来获取您需要的部分。如果你只是控制台输出 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);
})