简体   繁体   中英

How open internet explorer window, navigate it on url and get her document(HTMLDocument or InternetExplorer) using c# and mshtml library

How open internet explorer window or tab, navigate it and get her document(HTMLDocument or InternetExplorer) using c# and mshtml library. The type of IE object should be HTMLDocument or InternetExplorer.

If you want an interactive-automated instance of IE add a (COM) reference to Microsoft Internet Controls ;

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);
}
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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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