javascript - Web Scraper 返回 Null 值
问题描述
我正在尝试将数据导入本地应用程序,以获取从篮球参考网站收集的大学篮球统计数据。目前,我有能够收集玩家平均值的代码,并希望将其推断为玩家总数。这是我将用于此示例的 URL:https ://www.sports-reference.com/cbb/players/lindell-wigginton-1.html 。
这是我正在使用的代码的子集:
request(url, (err, res, html) => {
if (!err && res.statusCode == 200) {
// Load page HTML
const $ = cheerio.load(html);
/****** Get player Per Game stats ******/
// Push each value to a stats array
$("#players_per_game td").each((i ,el) => {
const item = $(el).text();
stats.push(item);
});
/****** Get Player Totals ******/
$("#players_totals td").each((i ,el) => {
const item = $(el).text();
totals.push(item);
});
}
});
球员每场比赛的统计数据填充得很好,但球员总数数组仍然为空。这是我在爬虫中通过“players_per_game”id 引用的 Per Game 表的页面 HTML:
<table class="row_summable sortable stats_table now_sortable" id="players_per_game" data-cols-to-freeze="1"><caption>Per Game Table</caption>
这是同一张表,其中刮板中的引用不起作用:
<table class="row_summable sortable stats_table now_sortable" id="players_totals" data-cols-to-freeze="1"><caption>Totals Table</caption>
然后我从那里引用<td>
标签来获取数据;但是,这仅适用于每场比赛,而不是球员总数。我在这里想念什么?
解决方案
推荐阅读
- javascript - 根据线的位置添加文本标签(画布)
- java - Lombok 和 jackson - 冲突/不明确的属性名称定义
- java - Powermock:java.lang.ClassCastException
- sharepoint-2013 - SharePoint - 如何阻止特定用户访问网站
- python - 使用海龟的while循环问题
- c# - C#忽略两个字符之间的多个字符串
- android - 首先从大小为 0 的单例类返回列表中改造 GET 调用
- sql - 如何在postgresql中连接两个表以求和
- javascript - 在上传前使用拖放和重新排序上传文件
- flutter - 无法在定位器服务中注册模型