服务器拿到模拟浏览器渲染的结果,可模拟dom操作。
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://www.tucao.one/index.php?m=member&c=index&a=login&forward='); //console.log输出内容 page.on('console', msg => console.log('console.log:', msg.text())); //注入脚本 const dimensions = await page.evaluate(async () => { //将js注入网页 async function timeout(t) { return new Promise((resolve, reject) => { setTimeout(() => resolve(), t); }); } await timeout(100) console.log('网页中输入') return { cookie: document.cookie, // content: $('body').html(), } }); console.log('输出内容:', dimensions); await browser.close(); })();
能拿到网页中的对象数据。