- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在控制台应用程序中使用 Web 浏览器控件,它是以编程方式创建的。它通过一个 url 并使用 DrawToBitmap 将页面保存为图像文件。
它似乎适用于许多 URL,但不适用于某些 URL,包括保存空白页面的 www.google.co.uk。 IBM.com 和 microsoft.com 工作,认为这可能与网站进行重定向有关。
这是代码:
int width = -1;
int height = -1;
// Load the webpage into a WebBrowser control
WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
wb.Navigated += new WebBrowserNavigatedEventHandler(wb_Navigated);
wb.AllowNavigation = true;
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Debug.WriteLine("Loading loop..");
Application.DoEvents();
}
// Set the size of the WebBrowser control
wb.Width = width;
wb.Height = height;
if (width == -1)
{
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
Debug.WriteLine("Saved");
Application.Exit();
最佳答案
你可能是想在它加载完成之前保存,检测WB是否满载是WB控制的最大问题,我多年来开发了几种方法,所以它涉及很多工作,并且有各种各样的方法你将需要实现。
另外,不要忘记,一些 HTML 数据可能正在加载到框架中,因此您可能需要获取对框架的引用并对每个框架和这些框架中的所有框架执行相同的操作(必须检测无限嵌套的嵌套框架)并添加到您的对象引用中以供使用)- 可靠的加载完整检测也需要帧引用,单独检查 readystate 或 .busy 是非常不可靠的,您的代码几乎肯定会在大多数情况下崩溃。查看我的一些与 WB 相关的帖子以获取更多信息,或者:Webbrowser Control Limitations
另外,如果您需要更多帮助,请告诉我,我可以为您提供有关检测加载完成的方法的指示。
关于asp.net - C# WebBrowser 控件将网页另存为图片,重定向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9121870/
运行这一行: webbrowser.open(page.path, new=0, autoraise=True) 我总是在新标签页中打开页面。 我怎样才能将它放在与它应该使用 new=0 相同的选项卡
基于 MSDN 上的这篇文章:How To Determine When a Page Is Done Loading in WebBrowser Control ,并且从过去关于 StackOver
我不明白为什么这行简单的代码行不通: // Bulding tree var declaration = new XDeclaration("1.0", "UTF-8", "yes"); var ro
这些是等价的吗? WebBrowser.Navigate('http://google.com'); 和 WebBrowser.Stop(); WebBrowser.Navigate('http://
我需要获取有关 Webbrowser 的滚动条(位置、大小、可见性)的信息控制外部应用程序,我尝试使用 GetScrollBarInfo来 self 之前的功能 question ,但该函数总是返回
目前在带有 WebBrowser 的 vb6 项目中,我遇到了一个问题。我想在我的应用程序中显示 adsense 广告,所以我创建了一个 html 页面并将文件放入服务器(adsense 批准),我尝
Windows Phone 8 应用程序,WebBrowser 控件。我通过 NavigateToString 加载了一大块 HTML (设置后 IsScriptEnabled=true )。一段时间
我有一个嵌入 WebBrowser 的 native Windows 应用程序, IE。 CLSID_WebBrowser 8856F961-340A-11D0-A96B-00C04FD705A2 S
提前致谢。 在我的应用程序中,我将 WebBrowser 控件替换为 Microsoft 的 WebView2 . 我想知道 WebView2 中 WebBrowser 控件的以下成员的等价物。 We
我怎样才能让 Web 浏览器调用自定义方案来启动 Activity,然后我想按下后退按钮但不返回 Web 浏览器。 我只想在调用网络浏览器然后调用我的方案启动另一个 Activity 时实现转发。当我
我们的目标是:嵌入在 .net winform 中的支持 Watin 的浏览器测试。 目前,我们正在使用 .net WebBrowser 控件将浏览器行为嵌入到 winform 中。我们使用如下代码将
我正在使用将 WebBrowser 控件嵌入到 Windows 窗体中的应用程序,我注意到一个严重的内存泄漏问题。在阅读了互联网上的其他类似案例后,问题似乎出在 IE 上。 我问过其他人是如何解决这个
我使用了“LoadCompleted”事件,基本上一旦收到该事件,我就需要截取屏幕截图(我已经构建)。问题是一旦这个事件结束,屏幕截图就只是空白(页面还没有加载),只有当我延迟 5-10 秒时,屏幕截
我试图自动打开多个用户配置文件,给定几个不同网站上的名称列表,但我找不到在新窗口中打开链接的方法,这意味着我无法对我打开的不同网站进行排序自己的橱窗收藏。 这是我的代码: import webbrow
我使用 vb.net + wpf+ System.Windows.Forms.WebBrowser 在 wpf 表单上显示网页内容。 此网站“http://manuim.com/laisha/”在控件
有没有办法检查用户是否安装了 PDF 阅读器? 也许使用 ActiveX 组件? 请你帮助我好吗? 最佳答案 不,我不这么认为 - 但默认情况下你总是可以通过谷歌的 PDF 阅读器直接链接你的链接 -
尝试在 WPF(C#/XAML、.NET 4.0)WebBrowser 应用程序中测试基本浏览器概念。到目前为止,唯一的问题是以编程方式缩放。有没有人有这方面的经验? MSDN 没有列出任何内容:ht
首先是一些定义,以保持清楚。 User: A live person, using the software Client: A company that is paying for a custom
尝试使用 webBrowser.Navigate("https://home.nest.com/") 加载页面时,我不断收到脚本错误.它会从我的普通互联网浏览器中正常显示,但不会在我的程序中显示。 谁
显然,WPF WebBrowser control 存在一些严重的键盘和焦点问题。 .我已经组装了一个简单的 WPF 应用程序,只有一个 WebBrowser 和两个按钮。该应用程序加载一个非常基本的
我是一名优秀的程序员,十分优秀!