使用 puppeteer 获取源代码 html

get source html with puppeteer

我已经在使用 puppeteer 抓取 我的页面,但是,我还需要原始 html (基本上是页面源)。

我知道我可以获取原始文件 html,但也许 puppeteer 已将其保存在某处。

puppeteer 是否在 goto() 之后保存页面源代码?

goto 方法 returns 解析为主要资源响应的承诺。所以你可以这样做:

const response = await page.goto(url);
console.log(await response.text());

但我建议使用 page.content() 方法获取页面的完整 HTML 内容,包括文档类型。详细了解 content