Beispiel #1
0
        /// <summary>
        /// Dom单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void On_DomClick(object sender, DomMouseEventArgs e)
        {
            //屏蔽页面点击事件
            e.PreventDefault();
            e.StopPropagation();

            var ele = e.CurrentTarget.CastToGeckoElement();

            ele = e.Target.CastToGeckoElement();
            GeckoHtmlElement geckoHtmlElement = (GeckoHtmlElement)ele;
            string           searchElement    = geckoHtmlElement.OuterHtml;

            if (!searchElement.Contains("firefinder-match-red"))
            {
                //在datagridview中显示选中行的内容
                GeckoHtmlElement[] geckoHtmlEle = new GeckoHtmlElement[1];
                geckoHtmlEle[0] = geckoHtmlElement;

                if (geckofxType.Equals(GeckofxWebbrowerType.General))
                {
                    InsertDataGridRow(dgv, geckoWebBrowser, geckoHtmlEle);
                }
                else if (geckofxType.Equals(GeckofxWebbrowerType.ListDetails))
                {
                    InsertDataGridRow(dgv, geckoWebBrowser, geckoHtmlEle);
                }
                else if (geckofxType.Equals(GeckofxWebbrowerType.UrlModel))
                {
                    try
                    {
                        GeckoAnchorElement d   = (GeckoAnchorElement)geckoHtmlElement;
                        string             URL = d.Href;

                        InsertDataGridRow(GeckofxWebbrowerType.UrlModel, dgv, geckoWebBrowser, geckoHtmlEle);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("请获取链接!");
                        return;
                    }
                }

                ruleStyle.AddClass("firefinder-match-red", ele);
            }
            else
            {
                //在浏览器中标记红圈
                ruleStyle.RemoveClass("firefinder-match-red", ele);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Dom双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void On_DomDoubleClick(object sender, DomMouseEventArgs e)
        {
            //屏蔽页面点击事件
            e.PreventDefault();
            e.StopPropagation();

            var ele = e.CurrentTarget.CastToGeckoElement();

            ele = e.Target.CastToGeckoElement();
            GeckoHtmlElement geckoHtmlElement = (GeckoHtmlElement)ele;

            //短xpath
            var xpath1 = xpathHelper.GetSmallXpath(ele);

            //var xpath2 = xpathHelper.GetXpath(ele);
            if (xpath1.Contains("tr"))
            {
                string demo = xpath1.Substring(xpath1.IndexOf("tr"));
                try
                {
                    demo = demo.Substring(0, demo.IndexOf("/"));
                }
                catch (Exception)
                {
                }
                xpath1 = xpath1.Replace(demo, "tr");
            }
            else if (xpath1.Contains("li"))
            {
                string demo = xpath1.Substring(xpath1.IndexOf("li"));
                try
                {
                    demo = demo.Substring(0, demo.IndexOf("/"));
                }
                catch (Exception)
                {
                }
                xpath1 = xpath1.Replace(demo, "li");
            }

            if (string.IsNullOrWhiteSpace(xpath1))
            {
                return;
            }
            var xresult  = geckoWebBrowser.DomDocument.EvaluateXPath(xpath1);
            var nodes    = xresult.GetNodes();
            var elements = nodes.Select(x => x as GeckoElement).ToArray();


            if (geckofxType.Equals(GeckofxWebbrowerType.General))
            {
            }
            else if (geckofxType.Equals(GeckofxWebbrowerType.ListDetails))
            {
            }
            else if (geckofxType.Equals(GeckofxWebbrowerType.UrlModel))
            {
                foreach (var item in elements)
                {
                    try
                    {
                        GeckoAnchorElement d   = (GeckoAnchorElement)geckoHtmlElement;
                        string             URL = d.Href;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("链接列表有问题,请检查!");
                        return;
                    }
                }
            }

            ruleStyle.AddClass("firefinder-match-red", elements);
            InsertDataGridRow(GeckofxWebbrowerType.UrlModel, dgv, geckoWebBrowser, elements);
        }