【发布时间】:2023-03-13 18:14:01
【问题描述】:
我正在使用剧作家从页面中抓取一些数据。我需要调用一个页面函数来更改浏览器的状态以收集更多信息。
从数据属性中获取函数名然后在页面上调用该函数的语法是什么?
我不断收到错误消息:UnhandledPromiseRejectionWarning: page.evaluate: Evaluation failed: TypeError: cb is not a function
这是我目前所拥有的:
const { chromium} = require("playwright");
(async()=>{
this.browser = await chromium.launch({
headless: true,
});
this.context = await this.browser.newContext();
this.page = await this.context.newPage();
this.page.goto('http://fakeExample.org')
const callbackHandle = await this.page.$('[data-callback]');
const cbName = await callbackHandle.evaluate(element=>element.getAttribute('data-callback')); //returns actual page function name 'myPageFunction'
this.page.evaluate((cb) => {
cb() //should call myPageFunction() on the page
}, cbName)
})()
【问题讨论】:
标签: javascript dom puppeteer playwright