經過工具或者命令方式安裝html
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
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 }); } }