2

如何使用 c# 和 mshtml 库打开 Internet Explorer 窗口或选项卡、导航并获取她的文档(HTMLDocument 或 InternetExplorer)。IE 对象的类型应该是 HTMLDocument 或 InternetExplorer。

4

2 回答 2

7

如果您想要 IE 的交互式自动化实例,请添加对Microsoft Internet Controls的 (COM) 引用;

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);
}
于 2012-10-18T12:55:37.813 回答
-1
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;
于 2017-01-24T07:49:56.480 回答