Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用傀儡机刮取动态站点_Node.js_Salesforce_Puppeteer_Cheerio - Fatal编程技术网

Node.js 使用傀儡机刮取动态站点

Node.js 使用傀儡机刮取动态站点,node.js,salesforce,puppeteer,cheerio,Node.js,Salesforce,Puppeteer,Cheerio,我试图建立一个简单的刮刀,将刮网站。 我想获得用户的徽章和点数 所以我用cheerio和木偶演员来完成这个任务 这是我的代码--> profile参数目前还没有被使用,因为我只是在测试它 问题: 每当我运行这段代码时,我不会在控制台上打印任何内容,如果我尝试不使用Puppeter,那么我只会得到没有任何数据的html。 我的预期结果是徽章和积分的数量 让我知道这个代码有什么问题 谢谢一切都是正确的。您所要做的就是wait您的getPage调用,因为它是异步的。试试这个 .get("/:profi

我试图建立一个简单的刮刀,将刮网站。 我想获得用户的徽章和点数

所以我用cheerio和木偶演员来完成这个任务

这是我的代码-->

profile参数目前还没有被使用,因为我只是在测试它

问题: 每当我运行这段代码时,我不会在控制台上打印任何内容,如果我尝试不使用Puppeter,那么我只会得到没有任何数据的html。 我的预期结果是徽章和积分的数量

让我知道这个代码有什么问题


谢谢

一切都是正确的。您所要做的就是
wait
您的
getPage
调用,因为它是异步的。试试这个

.get("/:profile", async (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 = await getPage(url);
  const $ = cheerio.load(html);
  const span = $('.tds-tally__count.tds-tally__count_success');
  console.log(span.text());

});
还需要像这样放置
async
-
async(req,res,next)

.get("/:profile", async (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 = await getPage(url);
  const $ = cheerio.load(html);
  const span = $('.tds-tally__count.tds-tally__count_success');
  console.log(span.text());

});