Puppeteer保存html,PuppeteerSharp读取页面完整HTML(.NetCore)
using (Browser browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))
{
using (var page = await browser.NewPageAsync())
{
//設置瀏覽器的頁面大小
await page.SetViewportAsync(new ViewPortOptions
{
Width = 1024,
Height = 768
});
await page.GoToAsync("http://www.baidu.com");
var html = await page.GetContentAsync();
var sourceFile = "";
var memoryStream = new MemoryStream(Encoding.Default.GetBytes(html));
var sr = new StreamReader(memoryStream);
sourceFile = sr.ReadToEnd();
//針對源代碼進行分析
var te = new TextExtractor(sourceFile);
te.extract();
sr.Close();
//將頁面保存為圖片
//await page.ScreenshotAsync(@"D:\1.png",
// new ScreenshotOptions() { FullPage = true, Type = ScreenshotType.Png });
}
}
總結
以上是生活随笔為你收集整理的Puppeteer保存html,PuppeteerSharp读取页面完整HTML(.NetCore)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql8.0.13 32位下载_My
- 下一篇: 自动部署 php,Jenkins实现P