Google chrome devtools 从Puppeter访问document.documentElement
通过打开开发工具并键入以下内容,我可以访问任何URL的整个HTML:Google chrome devtools 从Puppeter访问document.documentElement,google-chrome-devtools,puppeteer,Google Chrome Devtools,Puppeteer,通过打开开发工具并键入以下内容,我可以访问任何URL的整个HTML: document.documentElement 我试图使用Puppeter复制相同的行为,但是,下面的代码片段返回{} const puppeteer = require('puppeteer'); // v 1.1.0 const iPhone = puppeteer.devices['Pixel 2 XL']; async function start(canonical_url) { const browser
document.documentElement
我试图使用Puppeter复制相同的行为,但是,下面的代码片段返回{}
const puppeteer = require('puppeteer'); // v 1.1.0
const iPhone = puppeteer.devices['Pixel 2 XL'];
async function start(canonical_url) {
const browserURL = 'http://127.0.0.1:9222';
const browser = await puppeteer.connect({browserURL});
const page = await browser.newPage();
await page.emulate(iPhone);
await page.goto(canonical_url, {
waitUntil: 'networkidle2',
});
const data = await page.evaluate(() => document.documentElement);
console.log(data);
}
返回:
{}
你知道我在这里做错了什么吗?正如文档所说,只能返回可序列化的值,例如document.documentElement.innerHTML。这是否回答了你的问题@谢谢你的建议,你发送的链接部分回答了这个问题。我还打开了一个关于木偶师的bug,详细信息在