【发布时间】:2020-06-20 17:09:34
【问题描述】:
我正在尝试构建一个简单的刮板来刮掉Trailblazer Profile 网站。 我想获取用户的徽章和积分数。
所以我使用cheerio 和puppeteer 来完成这个。
这是我的代码 -->
.get("/:profile", (req,res,next) => {
const url = "https://trailblazer.me/id/hverma99";
async function getPage(url) {
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto(url, {waitUntil: 'networkidle0'});
const html = await page.content(); // serialized HTML of page DOM.
await browser.close();
return html;
}
const html = getPage(url);
const $ = cheerio.load(html);
const span = $('.tds-tally__count.tds-tally__count_success');
console.log(span.text());
});
目前还没有使用 profile 参数,因为我只是在测试它。
问题: 每当我运行此代码时,我都不会在控制台上打印任何内容,如果我尝试不使用 puppeteer,那么我只会得到没有任何数据的 html。 我的预期结果是徽章和积分的数量。
让我知道这段代码有什么问题。
谢谢
【问题讨论】:
标签: node.js salesforce puppeteer cheerio