use*_*od2 2 javascript node.js puppeteer
我一直在研究 Puppeteer,并且能够获取innerHTML,但是,这也可能包含<script>我想要删除的内容。
我该如何实现这一目标?
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.example.com');
console.log(await page.evaluate(() => document.body.innerHTML));
Run Code Online (Sandbox Code Playgroud)
像这样的东西吗?
const innerHTML = await page.evaluate(() => {
for (const script of document.body.querySelectorAll('script')) script.remove();
return document.body.innerHTML;
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1729 次 |
| 最近记录: |