在 Nodejs 中使用 puppeteer 抓取数据,结果不同

Scrapping data with puppeteer in Nodejs, Results are different

我想从此 URL“https://www.loom.com/share/5b920dc1375f43fa9b622ac0a6ba7c52”
中删除文本“1 次浏览” Url 个图像:https://imgur.com/r8dbUbV

在浏览器控制台中它给出了完美的结果
Url 个图像:https://imgur.com/Z4XrR3f

但在 puppeteer 中它给出 'Record a loom'
Url 个图像:https://imgur.com/zL1varD

我在尝试不同的浏览器时发现了类似的问题。您的选择器在 Firefox 中对我来说工作得很好,但在 Chrome 中就不行了。我假设您将 Chrome 与 Puppeteer 一起使用,因为它是默认设置。如果是这样的话,我们很可能会遇到同样的问题。无论如何,试试这个选择器:

document.querySelector(`[class*="header-content"] span:nth-child(2)`)

快乐刮,干杯!