当尝试使用Chrome控制器为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();
}`发布于 2014-03-18 15:58:14
您使用的是WebBrowser控件。WebBrowser是IE。如果你想要Chrome,可以使用类似乌索溴铵或PhantomJS之类的东西。
就我个人而言,我只需编写PhantomJS脚本,您就可以呈现整个页面或定义一个视口大小,并将其直接呈现给图像。
https://stackoverflow.com/questions/22484498
复制相似问题