Example #1
0
 private void pageTimer_TimeOut(object sender, TimerWrapperEventArgs e)
 {
     mWebBrowser.BeginInvoke((MethodInvoker) delegate()
     {
         HtmlElement tmp = mWebBrowser.Document.GetElementById(TimerConfig.Id);
         if (tmp != null && currentActivity.MyIntent.ShowTimerCount)
         {
             tmp.InnerText = "";
         }
         Application.DoEvents();
         TimeOut();
     });
 }
Example #2
0
        void UpdateStatusMessage(string msg)
        {
            if (HostWebBrowserControl == null)
            {
                return;
            }

            HostWebBrowserControl.BeginInvoke(
                new MethodInvoker(delegate { Status = msg; }));
        }
 public static void SafeInvoke(
     this WebBrowser webBrowser,
     Action <WebBrowser> call)
 {
     if (webBrowser.InvokeRequired)
     {
         webBrowser.BeginInvoke(call, webBrowser);
     }
     else
     {
         call(webBrowser);
     }
 }
        public static T SafeInvoke <T>(
            this WebBrowser webBrowser,
            Func <WebBrowser, T> call)
        {
            if (!webBrowser.Visible)
            {
                throw new InvalidOperationException("The control is not visible.");
            }

            if (!webBrowser.InvokeRequired)
            {
                return(call(webBrowser));
            }

            var result    = webBrowser.BeginInvoke(call, webBrowser);
            var endResult = webBrowser.EndInvoke(result);

            return((T)endResult);
        }
Example #5
0
        public void AppendHtml(WebBrowser webBrowser1,
                               string strText,
                               bool scrollToEnd = true)
        {
            if (webBrowser1.InvokeRequired)
            {
                webBrowser1.BeginInvoke(new Action <WebBrowser, string, bool>(AppendHtml), webBrowser1, strText, scrollToEnd);
                return;
            }

            Global.WriteHtml(webBrowser1,
                             strText);

            if (scrollToEnd)
            {
                // 因为HTML元素总是没有收尾,其他有些方法可能不奏效
                webBrowser1.Document.Window.ScrollTo(0,
                                                     webBrowser1.Document.Body.ScrollRectangle.Height);
            }
        }
 public void AddScript(object source, System.Timers.ElapsedEventArgs e)
 {
     try
     {
         if (browser.InvokeRequired)
         {
             browser.BeginInvoke(new Action(delegate
             {
                 if (browser.Document == null || browser.Document.DomDocument == null || ((HTMLDocument)browser.Document.DomDocument).documentElement == null)
                 {
                     return;
                 }
                 if (browser.Document.GetElementById("ld") != null)
                 {
                     return;
                 }
                 foreach (HtmlElement i in browser.Document.GetElementsByTagName("a"))
                 {
                     if (i.GetAttribute("classname") == "button_primary ng-scope" || i.GetAttribute("classname") == "button_default button_primary")
                     {
                         AddTimer.Stop();
                         AddJavaScript();
                         HtmlElement j = browser.Document.GetElementById("ld");
                         j.Click      += delegate
                         {
                             ccc();
                             AddTimer.Start();
                         };
                     }
                 }
             }));
         }
         else
         {
             //宿主异常结束时,在这里结束
             Application.Exit();
         }
     }
     catch (Exception ex)
     {
     }
 }
Example #7
0
        public void GetInner(Dictionary <string, string> dic)
        {
            #region 详情页
            foreach (var item in dic)
            {
Contect:
                try
                {
                    m_blnDefLoaded = false;
                    m_browser2.Navigate(item.Key);
                    int intSleepIndex = 0;
                    while (!m_blnDefLoaded)
                    {
                        Thread.Sleep(100);
                        intSleepIndex++;
                        if (intSleepIndex > 100)
                        {
                            goto Contect;
                        }
                    }
                    System.Windows.Forms.HtmlDocument docIn = null;
                    m_browser2.BeginInvoke(new MethodInvoker(delegate()
                    {
                        docIn = m_browser2.Document;
                    }));
                    while (docIn == null)
                    {
                        Thread.Sleep(10);
                    }
                    if (docIn != null && docIn.Body != null)
                    {
                        string str = docIn.Body.InnerText;
                        //为确认本次访问为正常用户行为,请您协助验证。
                        if (Regex.IsMatch(str, "为确认本次访问为正常用户行为,请您协助验证"))
                        {
                            VerifyCode();
                            goto Contect;
                        }

                        HtmlElementCollection elemsIn = docIn.GetElementsByTagName("div");
                        if (elemsIn.Count == 8)
                        {
                            goto Contect;
                        }
                        if (elemsIn != null)
                        {
                            string strtyTel   = string.Empty;
                            string strtyUrl   = string.Empty;
                            string strtyEmail = string.Empty;
                            string strName    = string.Empty;
                            foreach (HtmlElement elIn in elemsIn)
                            {
                                if (elIn.GetAttribute("className").Equals("company_info_text"))
                                {
                                    string strMsg = elIn.InnerText;
                                    strMsg = Regex.Replace(strMsg, @"暂无|\s", "");
                                    int int1 = strMsg.IndexOf("电话:");
                                    int int2 = strMsg.IndexOf("地址:");
                                    strMsg = strMsg.Substring(int1, int2 - int1);
                                    string[] values = Regex.Split(strMsg, @"电话:|邮箱:|网址:");
                                    if (values.Length == 4)
                                    {
                                        strtyTel   = values[1];
                                        strtyEmail = values[2];
                                        strtyUrl   = values[3];
                                    }
                                    strtyTel   = string.IsNullOrEmpty(strtyTel) ? "暂无" : strtyTel;
                                    strtyEmail = string.IsNullOrEmpty(strtyEmail) ? "暂无" : strtyEmail;
                                    strtyUrl   = string.IsNullOrEmpty(strtyUrl) ? "暂无" : strtyUrl;


                                    //if (elIn.Children.Count == 10)
                                    //{
                                    //    strtyTel = elIn.Children[2].InnerText.Trim().Replace("电话: ", "");
                                    //    strtyEmail = elIn.Children[3].InnerText.Trim().Replace("邮箱: ", "");
                                    //    strtyUrl = elIn.Children[5].InnerText.Trim().Replace("网址: ", "");
                                    //}
                                    //else if (elIn.Children.Count == 11)
                                    //{
                                    //    strtyTel = elIn.Children[3].InnerText.Trim().Replace("电话: ", "");
                                    //    strtyEmail = elIn.Children[3].InnerText.Trim().Replace("邮箱: ", "");
                                    //    strtyUrl = elIn.Children[6].InnerText.Trim().Replace("网址: ", "");
                                    //}
                                }
                                else if (elIn.GetAttribute("className").Equals("row b-c-white company-content"))
                                {
                                    HtmlElementCollection els = elIn.Children[0].Children[0].Children;

                                    if (els.Count > 1)
                                    {
                                        strName = els[1].Children[0].Children[0].Children[0].InnerText;
                                    }

                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            T_Web_TianYanCha_POI ty = new T_Web_TianYanCha_POI();
                            ty.LegalPersonName = strName;
                            ty.Tel             = strtyTel;
                            ty.Email           = strtyEmail;
                            ty.Name            = item.Value;

                            DataTable dt = GetDataTable(new List <T_Web_TianYanCha_POI>()
                            {
                                ty
                            });
                            ExcelEX.DataTableToExcel(m_savepath, dt, true);
                            SendMsgToMainClientEx("+");
                        }
                    }
                }
                catch
                {
                    goto Contect;
                }
            }
            #endregion
        }
Example #8
0
        private void Start()
        {
            try
            {
start:
                m_blnLoaded = false;
                m_browser1.BeginInvoke(new MethodInvoker(delegate()
                {
                    m_browser1.Navigate(m_strListUrl);
                }));

                int intSleepIndex = 0;
                while (!m_blnLoaded)
                {
                    Thread.Sleep(100);

                    intSleepIndex++;
                    if (intSleepIndex >= 100)
                    {
                        break;
                        //goto start;
                    }
                }
                Thread.Sleep(1000);
                try
                {
                    //验证码判断
                    System.Windows.Forms.HtmlDocument doc = null;
                    m_browser1.BeginInvoke(new MethodInvoker(delegate()
                    {
                        doc = m_browser1.Document;
                    }));
                    while (doc == null)
                    {
                        Thread.Sleep(10);
                    }
                    if (doc != null && doc.Body != null)
                    {
                        //为确认本次访问为正常用户行为,请您协助验证。
                        if (Regex.IsMatch(doc.Body.InnerText, "为确认本次访问为正常用户行为,请您协助验证"))
                        {
                            VerifyCode();
                            goto start;
                        }
                        if (doc.Body.InnerText.Contains("没有找到相关结果"))
                        {
                            SendMsgToMainClientEx("-1");
                            Thread.Sleep(1000);
                            return;
                        }
                    }
                    if (m_blnGetCount)
                    {
                        if (doc != null)
                        {
                            //  int intOut = 0;
                            //goHere:
                            //  intOut++;
                            string strReg = @"共(\d+)页";
                            Match  match  = Regex.Match(doc.Body.InnerText, strReg);
                            if (match != null)
                            {
                                string strNum   = Regex.Match(match.Value, @"\d+").Value;
                                int    intCount = int.Parse(strNum);
                                SendMsgToMainClientEx("count:" + intCount);
                            }
                            else
                            {
                                Thread.Sleep(1000);
                                //if (intOut > 30)
                                //{
                                goto start;
                                //}
                                //goto goHere;
                            }
                        }
                    }

                    if (doc != null)
                    {
                        #region
                        HtmlElementCollection       elems = doc.GetElementsByTagName("div");
                        Dictionary <string, string> dic   = new Dictionary <string, string>();
                        try
                        {
                            GetUrlList(elems, ref dic);
                        }
                        catch
                        {
                            goto start;
                        }
                        if (dic.Count != 0)
                        {
                            GetInner(dic);
                        }
                        else
                        {
                            goto start;
                        }
                        #endregion
                    }
                    else
                    {
                        goto start;
                    }
                }
                catch
                {
                    goto start;
                }
            }
            catch
            { }
            finally
            {
                Application.Exit();
                Process.GetCurrentProcess().Kill();
            }
        }
Example #9
0
 public void webBrowsershow(string url)
 {
     sankeyBrowser.BeginInvoke(new Action <string>((Url) => { sankeyBrowser.Navigate(Url); }), url);
 }