boo*_*aik 5 mutation-observers puppeteer
我想要像无头 chrome 中的 mutationobserver 一样跟踪更改的 DOM。所以我在学习 puppeteer 库,但不知道如何使用。
可以在 puppeteer 中跟踪 DOM 变化吗??谢谢
小智 6
好吧,您可以将自定义代码注入浏览器。
单程:
await page.evaluate(() => {
const observer = new MutationObserver(
function() {
// communicate with node through console.log method
console.log('__mutation')
}
)
const config = {
attributes: true,
childList: true,
characterData: true,
subtree: true
}
observer.observe(target, config)
})
Run Code Online (Sandbox Code Playgroud)
在您的节点脚本中:
page.on('console', async (msg) => {
if (msg.text === '__mutation') {
// do something...
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2916 次 |
| 最近记录: |