Beispiel #1
0
 //读取网页内容
 public void ReadDoc(IHTMLDocument2 doc)
 {
     log.WriteLog("解析网页【" + doc.location.href + "】DOM结构");
     foreach (IHTMLElement item in doc.all)
     {
         if (item != null && item.tagName != null)
         {
             if (item.tagName.ToUpper().Equals("FRAME") ||
                 item.tagName.ToUpper().Equals("IFRAME"))
             {
                 mshtml.IHTMLFrameBase2 iFrame         = (mshtml.IHTMLFrameBase2)item;
                 mshtml.IHTMLDocument2  iHTMLDocument2 = iFrame.contentWindow.document;
                 ReadDoc(iHTMLDocument2);
             }
             else
             {
                 parseElement(item);
             }
         }
     }
 }
Beispiel #2
0
        /*插入远程JS填屏插件*****************************************************************************************************************************/
        /// <summary>
        /// 时间:2016年9月14日13:54:38
        /// 2:在当前网页所有的IFrame中查找(iframe.src like url )
        ///    a.先找到IFrame.doc
        ///    b.在DOC中插入远程JS插件
        /// </summary>
        /// <param name="like_url"></param>
        public void OnDocumentComplete_query_iframe_like_url(string like_url)
        {
            /**日志**/
            this.methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;//程序执行位置代码块的方法名
            this.msg        = methodName + "进入此方法!";
            /***/
            util.log_to(this.Debug_config, this.methodName, this.msg);
            /**日志**/


            mshtml.HTMLDocument   document = (mshtml.HTMLDocument)webBrowser.Document;
            mshtml.HTMLDocument   doc      = (mshtml.HTMLDocument)webBrowser.Document;
            mshtml.IHTMLDocument2 doc2     = (mshtml.IHTMLDocument2)webBrowser.Document;
            mshtml.IHTMLDocument3 doc3     = (mshtml.IHTMLDocument3)webBrowser.Document;
            mshtml.IHTMLDocument4 doc4     = (mshtml.IHTMLDocument4)webBrowser.Document;
            mshtml.IHTMLDocument5 doc5     = (mshtml.IHTMLDocument5)webBrowser.Document;


            mshtml.IHTMLElement img = (mshtml.IHTMLElement)doc2.all.item("button", 0);
            int frames             = doc.parentWindow.frames.length;
            int doc3_iframe_lenght = doc3.getElementsByTagName("iframe").length; //iframe 数量   //int doc2_iframe_lenght=doc2.getElementsByTagName("iframe").length; //iframe 数量 e不能正常出数
            int inputcount         = doc2.all.length;

            this.msg = "\n frames:" + frames + " \n doc3_iframe_lenght:" + doc3_iframe_lenght;
            util.log_to(this.Debug_config, this.methodName, this.msg);


            /*******  第一层--------查找当前首层网页里》所有(IFrame)*******/
            if (doc3 != null)
            {
                foreach (IHTMLElement iframe_obj in doc3.getElementsByTagName("iframe"))
                {
                    //判断-当前IFrame是否匹配 >iframe.src( Contains == Like)
                    string iframe_obj_src = iframe_obj.getAttribute("src").ToString();
                    this.msg = "IFrame.name=" + iframe_obj.getAttribute("name").ToString();
                    util.log_to(this.Debug_config, this.methodName, this.msg);

                    if (iframe_obj_src.Contains(like_url))
                    {
                        //取出匹配到的(网页文档-Document2)
                        mshtml.IHTMLFrameBase2 FrameBase2 = (mshtml.IHTMLFrameBase2)iframe_obj;
                        mshtml.IHTMLDocument2  Document2  = FrameBase2.contentWindow.document;

                        string iframe_name = iframe_obj.getAttribute("name").ToString();
                        this.msg = this.methodName + " \nLv5>找到匹配的URL-IFrame.name=>" + iframe_name + "\nLv5>*****找到匹配的URL-IFrame.src=>" + iframe_obj_src + " 包含匹配字符〉" + like_url;
                        util.log_to(this.Debug_config, this.methodName, this.msg);

                        //@"\url_remote_js.txt"--获取配置文件中JS的URL
                        string url_remote_js = util.getFilename("url_remote_js");

                        util.add_doc_element_test(Document2, url_remote_js);

                        //string iframe_obj_name = iframe_obj.getAttribute("name").ToString();
                        //iframe_name_arrylist.Add(iframe_obj_name);//将找到的Iframe.name 属性保存起来
                        /***************************/
                    }
                    else
                    {
                        this.msg = "\nLv1>*URL-IFrame.src=> " + iframe_obj_src + " 不包含匹配字符〉" + like_url;
                        util.log_to(this.Debug_config, this.methodName, this.msg);
                    }
                }
            }
            else
            {
                this.msg = "doc3=null";
                util.log_to(this.Debug_config, this.methodName, this.msg);
            }
        }