C# 網(wǎng)頁(yè)截圖全攻略:三種技術(shù)與 Chrome 路徑查找指南
全局配置
string url = "https://blog.csdn.net/sunshineGGB/article/details/122316754";
一、PuppeteerSharp
1、安裝
NuGet搜索安裝[PuppeteerSharp]或者在程序包管理器控制臺(tái) Install-Package PuppeteerSharp
2、核心代碼
string html = PageSourceCodeHelper.GetWebCode1(url, "UTF-8");
PuppeteerHelper.PuppeteerScreenShot(html);
二、Selenium
1、安裝庫(kù)文件
和[PuppeteerSharp]一樣安裝下方庫(kù)文件
Selenium.WebDriver
Selenium.WebDriver.ChromeDriver
2、核心代碼
var filePath = AppDomain.CurrentDomain.BaseDirectory;
SeleniumHelper.SeleniumScreenshot(url, "mycsdn.png");
三、HtmlToImage
1、安裝庫(kù)文件
和[PuppeteerSharp]一樣安裝下方庫(kù)文件
Select.HtmlToPdf.NetCore
System.Drawing.Common
2、核心代碼
HtmlToPdfHelper.HtmlToPdfScreenShot(url);
關(guān)于如何在使用C#找到Windows上的chrome.exe路徑的問題有些頭疼
原因如下:
1、沒安裝Google Chrome,只是將chrome的環(huán)境安裝在本地如代碼的bin文件夾下
2、安裝了Google Chrome,通過系統(tǒng)盤的默認(rèn)安裝路徑如"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"或ChromeHTML通過注冊(cè)表尋找
參考
2、Selenium之cannot find Chrome binary錯(cuò)誤
3、How do I use C# to get the path to chrome.exe on Windows?
4、在linux上安裝谷歌瀏覽器并且使用selenium操控
本文來(lái)自博客園,作者:GoodTimeGGB,轉(zhuǎn)載請(qǐng)注明原文鏈接:http://www.rzrgm.cn/goodtimeggb/p/18687930

浙公網(wǎng)安備 33010602011771號(hào)