简体   繁体   English

在没有C#Webbrowser控件的情况下控制Web浏览器

[英]Controlling a webbrowser without c# webbrowser control

I want to be able to launch multiple browser windows and get the html from them and interact with them like I can with the .net web browser control. 我希望能够启动多个浏览器窗口并从中获取html并与它们进行交互,就像使用.net Web浏览器控件一样。 The problem is the c# web browser control requires STA threading and that makes my program slower and error prone. 问题是c#Web浏览器控件需要STA线程,这会使我的程序变慢并且容易出错。 Is their a way I can talk to the real IE browser or even Chrome, Firefox etc and do this? 他们是我可以与真正的IE浏览器甚至Chrome,Firefox等交谈的一种方式吗?

I know there is paid third party solutions and stuff but I was wondering if anybody knew of any free libraries that are reliable and work. 我知道有付费的第三方解决方案和东西,但我想知道是否有人知道任何可靠且有效的免费库。 I can't use HttpWebRequest for what I am doing, so don't suggest that please. 我不能将HttpWebRequest用于我正在做的事情,所以请不要建议。

I will be running on Windows and using C#. 我将在Windows上运行并使用C#。

I have used WebKit.NET. 我已经使用过WebKit.NET。 Its free and works great (supports flash, css, renders correctly, has a javascript engine). 它是免费的,而且效果很好(支持Flash,CSS,正确呈现,具有JavaScript引擎)。 It may or may not be to extensive for what you are doing. 它可能对您正在做的事情有广泛的影响,也可能没有。

http://webkitdotnet.sourceforge.net/ http://webkitdotnet.sourceforge.net/

There are plenty of guides, and the demo has a fully featured tab system. 有很多指南,该演示具有功能齐全的选项卡系统。

EDIT: I was fooling around with it, and made an enhanced version of the demo 编辑:我在鬼混,并制作了演示的增强版本

在此处输入图片说明

Awesomeium is a Webkit/Chromium (Chrome) based browser you can talk to via a .NET wrapper, much like the WebBrowser control. Awesomeium是一个基于Webkit / Chromium(Chrome)的浏览器,您可以通过.NET包装器与之交谈,就像WebBrowser控件一样。 I'm not sure on the STA threading requirement though. 我不确定STA线程要求。

As for STA Threading making your application "slower and error prone" -- This sounds odd, perhaps you should investigate solving this. 至于STA Threading,使您的应用程序“更慢且更容易出错”-听起来很奇怪,也许您应该研究解决问题的方法。

For IE (only). 对于IE(仅)。 Free: Microsoft Internet Controls 免费:Microsoft Internet控件

using SHDocVw;

Microsoft HTML Object Library Microsoft HTML对象库

using mshtml;

With these you can do things like 有了这些,您可以做类似的事情

foreach (InternetExplorer brIns in _allWindows)
            {
                var htmlDoc = brIns.Document as HTMLDocument;
                if (htmlDoc != null && htmlDoc.all.item(elementName) != null)
                {
                    var elem = htmlDoc.all.item(elementName) as HTMLInputElement;
                    if (elem != null && attributeName == null)
                    {
                        _ieCurrentDoc = htmlDoc;
                        _currentHtml = htmlDoc.documentElement.outerHTML;
                        return true;
                    }
                    if (elem != null && elem.getAttribute(attributeName) != null)
                    {
                        _ieCurrentDoc = htmlDoc;
                        _currentHtml = htmlDoc.documentElement.outerHTML;
                        return true;
                    }

                }
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM