码迷,mamicode.com
首页 > Web开发 > 详细

c# webBrowser全掌握

时间:2014-05-23 01:30:49      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:style   c   java   ext   a   int   

一、获取网页源代码

     1.不含有框架

      string s=WB1.DocumentText;  //webbrowser1命名为WB1,下同

      2.含有框架

      引用mshtml;          //位置C:\Program Files\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll

                object i_frame=0;     //第一个框架
                IHTMLDocument2 doc = FWB.Document.DomDocument as IHTMLDocument2;
                IHTMLFramesCollection2 frames = doc.frames as IHTMLFramesCollection2;
                IHTMLWindow2 frame = frames.item(ref i_frame) as IHTMLWindow2;
                IHTMLDocument2 frameDoc = frame.document as IHTMLDocument2;

                string s=frameDoc.Document.body.innerHTML;


二、获取网页元素

    1.根据ID

  HtmlDocument ele=   WB1.Document.getElementById("元素的ID");


三、执行JS函数

    1.用Navigate

      WB1.Navigate("javascript:postComment();");    //postComment为要执行的JS函数

     2.用IhtmlWindow2接口

            IHTMLWindow2 win2 = WB1.Document.Window.DomWindow as IHTMLWindow2;
            win2.execScript("function confirm(){return true;}", "javascript");

    3.用IhtmlDocument2接口的parentWindow
            IHTMLDocument2 doc2 = WB1.Document.DomDocument as IHTMLDocument2;
            doc2.parentWindow.execScript("function confirm() {return true;}", "javascript");



    

待续 

c# webBrowser全掌握,布布扣,bubuko.com

c# webBrowser全掌握

标签:style   c   java   ext   a   int   

原文地址:http://blog.csdn.net/xtfnpgy/article/details/26486659

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!