gpt4 book ai didi

puppeteer - 如何修复网络爬虫中的 'page.goto is not a function' 错误

转载 作者:行者123 更新时间:2023-12-03 18:40:30 24 4
gpt4 key购买 nike

我正在尝试使用 puppeteer 构建一个网络抓取工具,它会抓取我的 venmo 页面以查找付款。当我尝试运行我的脚本时,我收到一条错误消息,指出“page.goto 不是函数”

老实说,我不太确定从哪里开始

const puppeteer = require('puppeteer');

const url = 'generic.com';

(async () => {

//running in headless to observe what happens for now
const browser = await puppeteer.launch({headless: false});
const page = browser.newPage();
await page.goto(url);

let data = await page.evaluate(() => {

let amount = document.querySelector('span.bold.medium.green').innerText;
let timePayed = document.querySelector('a.grey_link').innerText;

return {
amount,
timePayed
}
});

console.log(data);

debugger;

await browser.close();

})();

这是我的错误信息
UnhandledPromiseRejectionWarning: TypeError: page.goto is not a function
at D:\venmoScraper\scraper.js:12:12
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:13212) UnhandledPromiseRejectionWarning: Unhandled promise
rejection. This error originated either by throwing inside of an async
function without a catch block, or by rejecting a promise which was not
handled with .catch(). (rejection id: 1)
(node:13212) [DEP0018] DeprecationWarning: Unhandled promise rejections
are deprecated. In the future, promise rejections that are not handled
will terminate the Node.js process with a non-zero exit code.

最佳答案

线,

const page = browser.newPage();

应该写成,
const page = await browser.newPage();

browser.newPage() 返回 Promise

关于puppeteer - 如何修复网络爬虫中的 'page.goto is not a function' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58333193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com