How to get all html data after all scripts and page loading is done? (puppeteer)

前端 未结 3 389
太阳男子
太阳男子 2021-01-04 23:23

Finally I figured how to use Node.js. Installed all libraries/extensions. So puppeteer is working, but as it was previous with Xmlhttp... it gets only template/body of the p

3条回答
  •  春和景丽
    2021-01-04 23:54

    If you want full html same as inspect? Here it is:

        const puppeteer = require('puppeteer');
    
        (async function main() {
          try {
            const browser = await puppeteer.launch();
            const [page] = await browser.pages();
    
            await page.goto('https://example.org/', { waitUntil: 'networkidle0' });
            const data = await page.evaluate(() => document.querySelector('*').outerHTML);
    
            console.log(data);
    
            await browser.close();
          } catch (err) {
            console.error(err);
          }
        })();
    

提交回复
热议问题