Example #1
0
        /*自定义挂载函数*****************************************************************************************************************************/
        /// <summary>
        /// 时间:2016年9月14日13:07:25
        /// 自定义挂载函数
        /// 1.加载文件内容
        ///   找到匹配的网址URL
        ///   再将些参数传给函数-OnDocumentComplete_query_iframe_like_url(like_url)处理
        /// </summary>
        /// <param name="pDisp"></param>
        /// <param name="URL"></param>
        public void OnDocumentComplete_start(object display, ref object URL)
        {
            this.Debug_config = util.getFilename("debug_config");                   /*初始化:读取Debug_Msg 配置是否==‘开’*/
            /**日志**/
            this.methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; //程序执行位置代码块的方法名
            this.msg        = methodName + "进入此方法!";
            /***/
            util.log_to(this.Debug_config, this.methodName, this.msg);
            /**日志**/


            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;

            string strUrl = URL.ToString();

            //this.strFilterKeys = this.get_file_str();
            this.msg = "当前网址=" + strUrl;
            util.log_to(this.Debug_config, this.methodName, this.msg);
            string Directory_path = System.Reflection.Assembly.GetExecutingAssembly().Location;

            /*********************(读取分隔符)*********************/
            // @"\url_fgf.txt";//读取分隔符
            string url_fgf_str = util.getFilename("url_fgf");
            //System.Windows.Forms.MessageBox.Show("分隔符-url_fgf_str.ToCharArray()=" + url_fgf_str.ToCharArray());


            /*********************(读取URL)*********************/
            //@"\url.txt";//读取URL
            string urls = util.getFilename("url");

            this.msg = "读取配置文件中》URL=" + urls;
            util.log_to(this.Debug_config, this.methodName, this.msg);

            /*********************(读取URL)*********************/
            string[] url_list = urls.Split(url_fgf_str.ToCharArray());

            foreach (string url in url_list)
            {
                if (strUrl.Contains(url))//判断-是否包含-URL网址
                {
                    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不能正常出数

                    this.msg = methodName + " \nLv5>匹配到网址-url:>" + url + "关键字的地址!\n frames=" + frames + "\n doc3_iframe_lenght=" + doc3_iframe_lenght;
                    util.log_to(this.Debug_config, this.methodName, this.msg);


                    //将当前网址URL-匹配到-文件中URL传给相关函数处理
                    this.OnDocumentComplete_query_iframe_like_url(url);
                }
                else
                {
                    this.msg = "没有找到匹配项=" + url;
                    util.log_to(this.Debug_config, this.methodName, this.msg);
                    //this.webBrowser.StatusText = strUrl;
                }
            }
        }
Example #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);
            }
        }