如何修复网页抓取工具中的“page.goto 不是函数”错误

rup*_*p16 4 puppeteer

我正在尝试使用 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();

})();
Run Code Online (Sandbox Code Playgroud)

这是我的错误信息

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.
Run Code Online (Sandbox Code Playgroud)

Md.*_*her 11

线,

const page = browser.newPage();
Run Code Online (Sandbox Code Playgroud)

应该写成,

const page = await browser.newPage();
Run Code Online (Sandbox Code Playgroud)

browser.newPage()作为Promise返回。