使用操纵符检测DOM中的更改_ MutationObserver正在工作

问题描述

我写了一个基于MutationObServer的函数

module.exports.crawler = async(page,link)=>{
    try {
        await page.goto(link,{ waitUntil: 'networkidle2' })
        await page.waitForSelector('#dbp')
        await page.waitForTimeout(10000)
        await page.exposeFunction('puppeteerLogMutation',() => {
          console.log('Mutation Detected: A child node has been added or removed.');
        });
        
      
        tables = await page.evaluate(async()=>{
          target = document.querySelector("#d02");
          const observer = new MutationObserver( mutations => {
            console.log(mutations)
          });
          observer.observe(target,{ childList: true });
         
          return data
        })
    console.log(tables)
    await page.close()
    } catch (error) {
        console.log(error)
    }

目标变量每20秒更改一次。我想检测变化。但这不起作用。有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)