是否可以在 puppeteer 中仅渲染单个 div(或使用任何选择器)?
示例:我的页面上有很多信息,我只想截图其中的一部分,一个 div,目前我使用截图 api 的 clip
选项
但有没有办法通过指定选择器来截屏?
最佳答案
有很多很酷的例子ElementHandle.screenshots tests ,例如:
await page.setViewport({width: 500, height: 500});
await page.goto(server.PREFIX + '/grid.html');
await page.evaluate(() => window.scrollBy(50, 100));
const elementHandle = await page.$('.box:nth-of-type(3)');
const screenshot = await elementHandle.screenshot();
关于node.js - Puppeteer 中的选择性渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54983177/