【发布时间】:2020-08-06 03:10:31
【问题描述】:
我在 node.js 中使用cheerio 来获取网站的元素。有了这个,我就可以制作星星和其他东西了。
我只想取以下代码中的文字:
<div id="graphDD3" class="pie-chart small" style="padding: 0px; position: relative;">
42.2%
<canvas class="flot-base" style="direction: ltr; position: absolute; left: 0px; top: 0px; width: 100px; height: 100px;" width="100" height="100"></canvas>
<canvas class="flot-overlay" style="direction: ltr; position: absolute; left: 0px; top: 0px; width: 100px; height: 100px;" width="100" height="100"></canvas>
</div>
我尝试了以下代码
let rate = $('#graphDD3').text().trim();
console.log(rate);
但我的控制台显示的是 0 而不是 42.2%
有人可以帮助我吗?或者你知道解决这个问题的另一种解决方案吗?
感谢那些愿意花时间帮助我的人。
【问题讨论】:
标签: html node.js puppeteer cheerio