我正在尝试使用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.
答案 0 :(得分:2)
行
const page = browser.newPage();
应写为
const page = await browser.newPage();
答案 1 :(得分:0)
除了上述有用的答案外,初学者可能还需要仔细检查 page.goto 上方的行是否具有正确的语法,即page = await browser.newPage();
而不是{{1 }}(不要忘记将其放在括号中)。
(我知道所问的问题有所不同,但认为这可能很有用,因为这是我遇到的' page.goto不是函数'错误)