Exemple #1
0
        public void ParseInnerHTML()
        {
            ParseHtmlHelper m_ParseHtmlHelper = new ParseHtmlHelper((string)MainWindow.strInnerHtml);

            m_ParseHtmlHelper.ExecuteAllRegex();
            orderInfos.Clear();
            int j = 0;

            for (int i = 0; i < m_ParseHtmlHelper.RegexMatchs[2].Count; i++)   /* SubOrderID Num */
            {
                string m_TradeID    = m_ParseHtmlHelper.RegexMatchs[0][j].Groups[1].Captures[0].Value;
                string m_Time_stamp = m_ParseHtmlHelper.RegexMatchs[1][j].Groups[1].Captures[0].Value;
                string m_Item       = m_ParseHtmlHelper.RegexMatchs[3][i].Groups[2].Captures[0].Value;
                m_Item = m_Item.Replace("\r", "");
                string m_Price        = m_ParseHtmlHelper.RegexMatchs[4][i].Groups[1].Captures[0].Value;
                string m_Num          = m_ParseHtmlHelper.RegexMatchs[5][i].Groups[1].Captures[0].Value;
                string m_Trouble      = m_ParseHtmlHelper.RegexMatchs[6][i].Groups[0].Captures[0].Value;
                string m_Contact      = m_ParseHtmlHelper.RegexMatchs[7][i].Groups[1].Captures[0].Value;
                string m_Trade_status = m_ParseHtmlHelper.RegexMatchs[8][i].Groups[2].Captures[0].Value;  /* need handle */
                m_Trade_status = m_Trade_status.Replace("\r", "");
                string m_Order_price = m_ParseHtmlHelper.RegexMatchs[9][i].Groups[1].Captures[0].Value;
                string m_Remark      = m_ParseHtmlHelper.RegexMatchs[10][i].Groups[0].Captures[0].Value;
                string m_Message     = m_ParseHtmlHelper.RegexMatchs[11][i].Groups[1].Captures[0].Value;

                if (m_Trade_status.Contains("</strong>"))
                {
                    m_Trade_status = m_Trade_status.Replace("</strong>", "");
                }

                orderInfos.Add(new OrderInfo()
                {
                    TradeID      = m_ParseHtmlHelper.RegexMatchs[0][j].Groups[1].Captures[0].Value,
                    Time_stamp   = m_ParseHtmlHelper.RegexMatchs[1][j].Groups[1].Captures[0].Value,
                    Item         = m_Item,
                    Price        = m_ParseHtmlHelper.RegexMatchs[4][i].Groups[1].Captures[0].Value,
                    Num          = m_ParseHtmlHelper.RegexMatchs[5][i].Groups[1].Captures[0].Value,
                    Trouble      = m_ParseHtmlHelper.RegexMatchs[6][i].Groups[0].Captures[0].Value,
                    Contact      = m_ParseHtmlHelper.RegexMatchs[7][i].Groups[1].Captures[0].Value,
                    Trade_status = m_Trade_status,
                    Order_price  = m_ParseHtmlHelper.RegexMatchs[9][i].Groups[1].Captures[0].Value,
                    Remark       = m_ParseHtmlHelper.RegexMatchs[10][i].Groups[0].Captures[0].Value,
                    Message      = m_Message
                });

                if (m_ParseHtmlHelper.RegexMatchs[0][j].Groups[1].Captures[0].Value.CompareTo(
                        m_ParseHtmlHelper.RegexMatchs[2][i].Groups[1].Captures[0].Value) != 0)
                {
                    j++;
                }
            }

            view.Source = orderInfos;

            this.OrderList.DataContext = view;
        }
        private async void GetInnerHTML()
        {
            try
            {
                var response = await webBrowser.EvaluateScriptAsync("myBytes=window.document.body.innerHTML;");

                if (response.Success && response.Result is IJavascriptCallback)
                {
                    response = await((IJavascriptCallback)response.Result).ExecuteAsync("This is a callback from EvaluateJavaScript");
                }

                MainWindow.strInnerHtml = (string)(response.Success ? (response.Result ?? "null") : response.Message);
                ParseHtmlHelper m_ParseHtmlHelper = new ParseHtmlHelper((string)MainWindow.strInnerHtml);
                m_ParseHtmlHelper.GetMessageUrl();

                for (int i = 0; i < m_ParseHtmlHelper.MessageUrlMatchs.Count; i++)
                {
                    string m_Message = m_ParseHtmlHelper.MessageUrlMatchs[i].Groups[1].Captures[0].Value;  /* need handle */
                    string ifrm_name = string.Format(@"frm{0}", i);
                    string JsCmd     = "document.body.insertAdjacentHTML(\"beforeEnd\", \"<iframe width='400' height='50' id='" + ifrm_name + "' src='" + m_Message + "'/>\");";
                    response = await webBrowser.EvaluateScriptAsync(JsCmd);

                    Random ran     = new Random(); /* 搞个随机数防检测 */
                    int    RandKey = ran.Next(200, 1500);
                    Thread.Sleep(RandKey);
                    JsCmd    = "var iFrame = document.getElementById('" + ifrm_name + "');var iFrameElement = iFrame.contentWindow.document.body.innerHTML;MyByte=iFrameElement;";
                    response = await webBrowser.EvaluateScriptAsync(JsCmd);

                    MainWindow.strMessageHtml += (string)(response.Success ? (response.Result ?? "null") : response.Message);
                }

                response = await webBrowser.EvaluateScriptAsync("myBytes=window.document.body.innerHTML;");

                if (response.Success && response.Result is IJavascriptCallback)
                {
                    response = await((IJavascriptCallback)response.Result).ExecuteAsync("This is a callback from EvaluateJavaScript");
                }

                MainWindow.strInnerHtml = (string)(response.Success ? (response.Result ?? "null") : response.Message);
            }
            catch (Exception e)
            {
                MessageBox.Show("Error while evaluating Javascript: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }