Puppeteer保存html,PuppeteerSharp读取页⾯完整
HTML(.Net。。。
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("www.baidu");
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);
sr.Close();
/
/将页⾯保存为图⽚
//await page.ScreenshotAsync(@"D:\1.png",
// new ScreenshotOptions() { FullPage = true, Type = ScreenshotType.Png });
}
}
>网页html下载

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。