Tag: 浏览器

.NET C#:WebBrowser控件Navigate()不加载目标URL

我正在尝试以编程方式通过WebBrowser控件加载网页,目的是测试页面及其JavaScript函数。 基本上,我想比较通过此控件运行的HTML和JavaScript与已知输出,以确定是否存在问题。 但是,我在创建和导航WebBrowser控件时遇到了麻烦。 下面的代码旨在将HtmlDocument加载到WebBrowser.Document属性中: WebBrowser wb = new WebBrowser(); wb.AllowNavigation = true; wb.Navigate(“http://www.google.com/”); 在Navigate()运行后通过Intellisense检查Web浏览器的状态时,WebBrowser.ReadyState为’Uninitialized’,WebBrowser.Document = null,并且它总体上看起来完全不受我的调用的影响。 在上下文中,我在Windows窗体对象之外运行此控件:我不需要加载窗口或实际查看页面。 要求规定需要简单地执行页面的JavaScript并检查生成的HTML。 非常感谢任何建议,谢谢!

如何为Web浏览器默认设置IE9?

我正在用C#.NET开发一个应用程序。 我想将IE9版本用于WebBrowser; IE9是否安装在系统上。 是否有可能将IE9与WebBrower一起使用,可能是我的系统中没有安装IE9?

webbrowser上的c#filenotfoundexception?

if (webBrowser1.DocumentText.IndexOf(“Page: 1”) != -1) 在上面这行我得到了这个例外 System.IO.FileNotFoundException未处理Message =“系统找不到指定的文件。(HRESULTexception:0x80070002)” 来源= “System.Windows.Forms的” StackTrace:位于Windows.msApplication1.Form1的System.Windows.Forms.WebBrowser.get_DocumentText()上的System.Windows.Forms.WebBrowser.get_DocumentStream()处的System.Windows.Forms.UnsafeNativeMethods.IPersistStreamInit.Save(IStream pstm,Boolean fClearDirty)。生成C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ GenerateWorklists \ GenerateWorklists \ Form1.cs中的ETGWorklists():位于C:\ Documents中的WindowsFormsApplication1.Form1.btnProcess_Click(Object sender,EventArgs e)的第603行和Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ GenerateWorklists \ GenerateWorklists \ Form1.cs:System.Windows.Forms.Button.OnClick上的System.Windows.Forms.Control.OnClick(EventArgs e)第55行(EventArgs) e)在System.Windows.Forms.Connd.WndProc(Message&m)的System.Windows.Forms.Control.WmMouseUp(Message&m,MouseButtons按钮,Int32单击)处的System.Windows.Forms.Button.OnMouseUp(MouseEventArgs […]

我应该如何使用multithreading正确调用WebBrowser?

问题范围: 我正在编写一个应用程序来保存从Bing和Google搜索中检索到的HTML。 我知道有一些类可以使用流来执行Web请求,例如这个例子 ,但是由于Google和Bing都使用Javascript和Ajax将结果呈现到HTML中,所以我无法简单地读取流并使用获取结果我需要。 对此的解决方案是使用WebBrowser类并导航到我想要的URL,以便浏览器本身将处理所有Javascript和Ajax脚本执行。 multithreading: 为了提高效率,我使用相同的表单应用程序为每个服务启动一个线程(一个用于Bing,一个用于Google)。 问题: 由于我需要WebBrowser,我已经为每个线程实例化了一个(此时为2)。 根据Microsoft的说法, known bug that prevents the DocumentCompleted event from firing if the WebBrowser is not visible and is not added to a visible form aswell ,则存在一个known bug that prevents the DocumentCompleted event from firing if the WebBrowser is not visible and is not added to a […]

如何在C#webbrowser中使用套接字代理?

如何使用winforms webbrowser控件将套接字指向代理IP /端口? Visual C#.NET附带的标准Web浏览器。 请帮助Visual C#.NET。

Webbrowser窃取焦点

我正在winforms app(c#)中使用webbrowser控件。 当它正在进行自动化操作时,我正在从我正在使用的窗口中失去焦点控制。 Web浏览器的forms也没有显示出来,我只是从控制中失去了焦点。 我现在写这条消息,我必须一次又一次地点击进入文本框…… 如何在webbrowser中禁用此类行为? 我创建了这样的隐形web浏览器: var br = new WebBrowser(); br.Visible = false; br.ScriptErrorsSuppressed = true; 请指教。

打开webbrowser,自动填写表单组件并提交

我们目前正在研究一种创建WPF / winforms应用程序的方法,我们可以在内部设置它: 自动将Web浏览器的新实例打开到预定义的URL 使用预定义数据自动完成必填字段 自动提交表单并等待下一页加载 使用预定义数据自动填写必填字段(第2页) 自动提交表单并等待下一页加载(等) 经过多次调查,我们唯一能找到的是通过以下方式打开网络浏览器: – object o = null; SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer(); IWebBrowserApp wb = (IWebBrowserApp)ie; wb.Visible = true; wb.Navigate(url, ref o, ref o, ref o, ref o); 任何建议/阅读建议将不胜感激如何完成该过程。

Web浏览器行为问题

我试图用.NET C#自动化Webbrowser。 问题是控件或我应该说IE浏览器在不同的计算机上表现得很奇怪。 例如,我点击链接并在第一台计算机上填充Ajax弹出窗体,如下所示,没有任何错误: private void btn_Start_Click(object sender, RoutedEventArgs e) { webbrowserIE.Navigate(“http://www.test.com/”); webbrowserIE.DocumentCompleted += fillup_LoadCompleted; } void fillup_LoadCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e) { System.Windows.Forms.HtmlElement ele = web_BrowserIE.Document.GetElementById(“login”); if (ele != null) ele.InvokeMember(“Click”); if (this.web_BrowserIE.ReadyState == System.Windows.Forms.WebBrowserReadyState.Complete) { web_BrowserIE.Document.GetElementById(“login”).SetAttribute(“value”, myUserName); web_BrowserIE.Document.GetElementById(“password”).SetAttribute(“value”, myPassword); foreach (System.Windows.Forms.HtmlElement el in web_BrowserIE.Document.GetElementsByTagName(“button”)) { if (el.InnerText == “Login”) { el.InvokeMember(“click”); } } web_BrowserIE.DocumentCompleted […]

截图方法生成黑色图像

在c#中未能使用control.drawtobitmap之后,我的第二个选择是获取桌面的屏幕截图并裁剪出所需的部分。 一旦我切换用户帐户,我的打嗝就出现了,虽然程序没有崩溃,一旦用户切换,程序只生成纯黑图像。 我用这个代码作为参考: WebBrowser.DrawToBitmap()或其他方法? 我认为逻辑上这是有道理的,因为这将有助于Windows节省资源。 在我的情况下,我有哪些选择/解决方案? 编辑1对代码进行了修改以进行测试: int c = 0; while (true) { try { c++; Rectangle formBounds = this.Bounds; Bitmap bmp = new Bitmap(formBounds.Width, formBounds.Height); using (Graphics g = Graphics.FromImage(bmp)) g.CopyFromScreen(formBounds.Location, Point.Empty, formBounds.Size); bmp.Save(“picture” + c.ToString() + “.jpg”); Thread.Sleep(5000); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } 这在用户帐户上完美运行,但是一旦我切换用户,它就会返回exception:句柄无效。 有任何想法吗? 编辑2: DrawToBitmap中的错误并不是随机的…如果我使用了您提供的代码: Bitmap bmp […]

C#如何通过WebBrowser自动单击按钮

点击页面的Html代码是: 我尝试使用此代码进行点击: webBrowser1.Document.GetElementById(“publishButton-ns”).InvokeMember(“click”); 但是没找到按钮。