Chrome网页截图
本文关键字:网页 Chrome | 更新日期: 2023-09-27 17:50:52
当尝试使用WebBrowser控制器为chrome执行网页截图的c#代码时,我得到的屏幕截图是由IE呈现的网页,而不是由chrome(我试图捕获的网站由chrome, FireFox和IE呈现不同)。
你能给我解释一下如何为Chrome而不是IE渲染的网页截图吗??Ps:我以前使用过ChromeDriver,但它只捕获网页的可见部分,谢谢你
这是获取网页屏幕截图的方法
`public static void TakeScreenShotChrome(WebBrowser WB, string url, string path)
// Load the webpage into a WebBrowser control WebBrowser
{
WB.ScrollBarsEnabled = false;
WB.ScriptErrorsSuppressed = true;
WB.Navigate(url);
while (WB.ReadyState != WebBrowserReadyState.Complete)
{
//Application.DoEvents();
Thread.Sleep(1000);
}
// Take Screenshot of the web pages full width
WB.Width = WB.Document.Body.ScrollRectangle.Width;
// Take Screenshot of the web pages full height
WB.Height = WB.Document.Body.ScrollRectangle.Height;
Bitmap bitmap = new Bitmap(WB.Width, WB.Height);
WB.DrawToBitmap(bitmap, new Rectangle(0, 0, WB.Width, WB.Height));
bitmap.Save(path,ImageFormat.Png);
WB.Dispose();
}`
您正在使用WebBrowser
控件。WebBrowser
为IE。如果你想要Chrome,使用Awesomium或PhantomJS。
就我个人而言,我只是脚本PhantomJS,你可以渲染整个页面或定义一个视口大小,并直接渲染到一个图像。