From e2888ba8456ac03a95b8c340b950e2079727ba01 Mon Sep 17 00:00:00 2001 From: sh <2022704648@qq.com> Date: Mon, 30 Dec 2019 17:38:56 +0800 Subject: [PATCH] 修改检察院名称跳转问题 --- FRControl/WebView.cs | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 20 deletions(-) diff --git a/FRControl/WebView.cs b/FRControl/WebView.cs index 6c2d094..0839fc6 100644 --- a/FRControl/WebView.cs +++ b/FRControl/WebView.cs @@ -13,6 +13,7 @@ namespace FRControl { public partial class WebView : Form { + private Timer timer1 = null; public WebView() { SetWebBrowserFeatures(11); @@ -69,25 +70,6 @@ namespace FRControl htmlElement.SetAttribute("target", "_self"); } - HtmlElementCollection elementCollection = this.webBrowser1.Document.GetElementsByTagName("b"); - - if (null != elementCollection) - { - foreach (HtmlElement elem in elementCollection) - { - - if (elem.GetAttribute("className").ToString().Equals("lanmu")) - { - elem.SetAttribute("className", "lanmuc"); - elem.Click += new HtmlElementEventHandler(elem_Click); - } - - //Console.WriteLine(elem.InnerHtml+",class="+ elem.GetAttribute("className").ToString()); - //Console.WriteLine(elem.GetAttribute("class").ToString()); - - } - } - this.webBrowser1.Document.Window.Error += new HtmlElementErrorEventHandler(Window_Error); //获取网页的最大size Size szba = new Size(webBrowser1.Document.Body.ScrollRectangle.Width, webBrowser1.Document.Body.ScrollRectangle.Height); @@ -111,9 +93,89 @@ namespace FRControl axIWebBrowser2.ExecWB(FRControl.ZoomBrowser.OLECMDID.OLECMDID_OPTICAL_ZOOM, FRControl.ZoomBrowser.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, xbili, IntPtr.Zero); + + this.elem_Click(); + //HtmlElementCollection elementCollection = this.webBrowser1.Document.GetElementsByTagName("b"); + //if (null != elementCollection) + //{ + // foreach (HtmlElement elem in elementCollection) + // { + // if (elem.GetAttribute("className").ToString().Equals("lanmu")) + // { + // elem.SetAttribute("className", "lanmuc"); + // elem.Click += new HtmlElementEventHandler(elem_Click); + // } + + // //Console.WriteLine(elem.InnerHtml+",class="+ elem.GetAttribute("className").ToString()); + // //Console.WriteLine(elem.GetAttribute("class").ToString()); + // } + //} + } + + + + public void elem_Click() + { + timer1 = new Timer(); + timer1.Interval = 100; + timer1.Enabled = true; + timer1.Tick += new EventHandler(jcyEventProcessor);//添加事件 + + + //HtmlElement elem = (HtmlElement)sender; + //String url = "https://www.12309.gov.cn" + elem.GetAttribute("url").ToString(); + //this.webBrowser1.Navigate(url); + //Console.WriteLine(url); + //Console.WriteLine(elem.InnerHtml + ",class=" + elem.GetAttribute("className").ToString()+"url:"+ elem.GetAttribute("url").ToString()); + } - public void elem_Click(object sender, EventArgs e) + public void jcyEventProcessor(object sender, EventArgs e) + { + + HtmlElementCollection elementCollection = this.webBrowser1.Document.GetElementsByTagName("b"); + bool isLoad = false; + if (null != elementCollection) + { + //Console.WriteLine(isLoad); + foreach (HtmlElement elem in elementCollection) + { + if (elem.GetAttribute("className").ToString().Equals("lanmu")) + { + isLoad = true; + //elem.SetAttribute("className", "lanmuc"); + //elem.Click += new HtmlElementEventHandler(elem_Click); + } + } + + } + if (isLoad) + { + //Console.WriteLine(isLoad); + timer1.Stop(); + timer1.Tick -= new EventHandler(jcyEventProcessor); + timer1 = null; + + HtmlElementCollection elementCollections = this.webBrowser1.Document.GetElementsByTagName("b"); + if (null != elementCollections) + { + foreach (HtmlElement elem in elementCollections) + { + if (elem.GetAttribute("className").ToString().Equals("lanmu")) + { + elem.SetAttribute("className", "lanmuc"); + elem.Click += new HtmlElementEventHandler(jcyClick); + } + + Console.WriteLine(elem.InnerHtml+",class="+ elem.GetAttribute("className").ToString()); + Console.WriteLine(elem.GetAttribute("class").ToString()); + } + + } + } + } + + public void jcyClick(object sender, EventArgs e) { HtmlElement elem = (HtmlElement)sender; String url = "https://www.12309.gov.cn" + elem.GetAttribute("url").ToString(); @@ -136,6 +198,13 @@ namespace FRControl } private void ReturnBtn_Click(object sender, EventArgs e) { + if (null != timer1) + { + timer1.Stop(); + timer1.Tick -= new EventHandler(jcyEventProcessor); + timer1 = null; + } + this.webBrowser1.Dispose(); this.Close(); } -- libgit2 0.21.4