如何打开Internet Explorer窗口或标签,导航,并获得使用C#和MSHTML库文件了(或HTMLDocument的InternetExplorer的)。 类型IE对象的应HTMLDocument的或InternetExplorer的。
Answer 1:
如果你想IE的交互自动化的实例增加一个(COM)参考Microsoft Internet控制 ;
private void Form1_Load(object sender, EventArgs e) {
var IE = new SHDocVw.InternetExplorer();
IE.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(OnNavigateComplete2);
object URL = "http://www.stackoverflow.com";
IE.Visible = true;
IE.Navigate2(ref URL);
}
public void OnNavigateComplete2(object pDisp, ref object url) {
var IE = (SHDocVw.InternetExplorer)pDisp;
MessageBox.Show(IE.Document.Title);
}
Answer 2:
InternetExplorer ie= new InternetExplorer();
ie.Navigate("www.example.com");
ie.Visible = true;
Thread.Sleep(5000);//wait until page loads
mshtml.HTMLDocument doc;
doc = ie.Document;
文章来源: How open internet explorer window, navigate it on url and get her document(HTMLDocument or InternetExplorer) using c# and mshtml library