1

Here, I am trying to get each players runs and matches using player-URL. When I passes selector within page.$$eval method and in callback element when I console it,I got nothing in it.

const stats = await page.$$eval(
    "div.score-top.sp.text-center > div.container > div.match-summary > div.row > div.col-sm-12 > div.match-in-summary > div.row > div.col-sm-5 > div.matches-runs-wickets > ul.list-inline ",
    (elements) => {
      console.log("elements", elements);
      return elements.map((match) => {
        return (obj = {
          matches: match.querySelector(" li:nth-Child(1) >span").innerText,
          runs: match.querySelector("li:nth-Child(2) > span").innerText,
        });
      });
    }
  );
  return stats;
}

but when I map over the callback element and return the object then I am getting runs and matches in stats variableThe code detail is mentioned here.

Yasin
  • 11
  • 1

2 Answers2

2

Everything that you console.log in eval function will be displayed in browser's console. See the console of the browser that you have opened and there you will see the logs that you are trying to print.

dangi13
  • 1,275
  • 1
  • 8
  • 11
1

In your example console.log is happening not on the node.js side, but inside of a headless browser's console. You can see messages if you launch puppeteer with headless: false option.

And if you'd like to receive such console messages in terminal, see this answer.

Vaviloff
  • 16,282
  • 6
  • 48
  • 56