1、html网页解析渲染后内容截图
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true
});
var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com")
;
await page.ScreenshotAsync(outputFile);
生成截图前也可以改变ViewPort:
await page.SetViewport(new ViewPortOptions
{
Width = 500,
Height = 500
});
2、html网页解析渲染后内容保存成pdf文件
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true
});
var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com")
;
await page.PdfAsync(outputFile);
向网页中注入HTML、执行Javascript(js)代码、Selector等待加载完的内容,等更多操作和使用Puppeteer Sharp使用方法,参考下面的文档。