Ejemplo n.º 1
0
        public void InsertDataGridRow(GeckofxWebbrowerType geckofxWebbrowerType, DataGridView dgv, GeckoWebBrowser geckoWebBrowser, params GeckoElement[] ele)
        {
            List <GeckoHtmlElement> geckoHtmlElementList = null;

            //设置xpath 获取html信息
            if (ele.Length == 1)
            {
                var xpathTxt = xpathHelper.GetSmallXpath(ele[0]);
                var xresult  = geckoWebBrowser.DomDocument.EvaluateXPath(xpathTxt);
                var nodes    = xresult.GetNodes();
                var elements = nodes.Select(x => x as GeckoElement).ToArray();
                geckoHtmlElementList = XpathHelper.FindHtmlTxt(true, elements);
            }
            else
            {
                geckoHtmlElementList = XpathHelper.FindHtmlTxt(true, ele);
            }

            if (geckofxWebbrowerType.Equals(GeckofxWebbrowerType.General))
            {
                foreach (GeckoHtmlElement element in geckoHtmlElementList)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    //文本
                    DataGridViewTextBoxCell fieldsNameCell = new DataGridViewTextBoxCell();
                    fieldsNameCell.Value = "字段" + (count++);
                    row.Cells.Add(fieldsNameCell);

                    DataGridViewTextBoxCell fieldsContentCell = new DataGridViewTextBoxCell();
                    fieldsContentCell.Value = element.TextContent;
                    row.Cells.Add(fieldsContentCell);

                    //下拉框
                    DataGridViewTextBoxCell fieldsTypeCell = new DataGridViewTextBoxCell();
                    fieldsTypeCell.Value = "抓取文本";
                    row.Cells.Add(fieldsTypeCell);

                    DataGridViewImageCell deleteCell = new DataGridViewImageCell();
                    deleteCell.Value = Image.FromFile(@"E:\Project\C#\SimpleCrawlProject\SimpleCrawlApp\Resources\1108658.png");
                    row.Cells.Add(deleteCell);

                    //隐藏浏览器句柄
                    DataGridViewTextBoxCell visibleGeckofxElementCell = new DataGridViewTextBoxCell();
                    visibleGeckofxElementCell.Value = element;
                    row.Cells.Add(visibleGeckofxElementCell);

                    //隐藏xpath
                    DataGridViewTextBoxCell visibleGeckofxXpathCell = new DataGridViewTextBoxCell();
                    visibleGeckofxXpathCell.Value = xpathHelper.GetSmallXpath(element);
                    row.Cells.Add(visibleGeckofxXpathCell);

                    //将元素插入datagridview控件中
                    dgv.Rows.Add(row);
                }
            }
            else if (geckofxWebbrowerType.Equals(GeckofxWebbrowerType.ListDetails))
            {
            }
            else if (geckofxWebbrowerType.Equals(GeckofxWebbrowerType.UrlModel))
            {
                foreach (GeckoHtmlElement element in geckoHtmlElementList)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    //文本
                    DataGridViewTextBoxCell fieldsNameCell = new DataGridViewTextBoxCell();
                    fieldsNameCell.Value = "字段" + (count++);
                    row.Cells.Add(fieldsNameCell);

                    DataGridViewTextBoxCell fieldsContentCell = new DataGridViewTextBoxCell();
                    fieldsContentCell.Value = element.TextContent;
                    row.Cells.Add(fieldsContentCell);

                    //下拉框
                    DataGridViewTextBoxCell fieldsTypeCell = new DataGridViewTextBoxCell();
                    fieldsTypeCell.Value = "抓取详情页链接";
                    row.Cells.Add(fieldsTypeCell);

                    DataGridViewImageCell deleteCell = new DataGridViewImageCell();
                    deleteCell.Value = Image.FromFile(@"E:\Project\C#\SimpleCrawlProject\SimpleCrawlApp\Resources\1108658.png");
                    row.Cells.Add(deleteCell);

                    //隐藏浏览器句柄
                    DataGridViewTextBoxCell visibleGeckofxElementCell = new DataGridViewTextBoxCell();
                    visibleGeckofxElementCell.Value = element;
                    row.Cells.Add(visibleGeckofxElementCell);

                    //隐藏xpath
                    DataGridViewTextBoxCell visibleGeckofxXpathCell = new DataGridViewTextBoxCell();
                    visibleGeckofxXpathCell.Value = xpathHelper.GetSmallXpath(element);
                    row.Cells.Add(visibleGeckofxXpathCell);

                    //将元素插入datagridview控件中
                    dgv.Rows.Add(row);
                }
            }
        }
Ejemplo n.º 2
0
        public void InsertDataGridRow(DataGridView dgv, GeckoWebBrowser geckoWebBrowser, params GeckoElement[] ele)
        {
            List <GeckoHtmlElement> geckoHtmlElementList = null;

            //设置xpath 获取html信息
            if (ele.Length == 1)
            {
                var xpathTxt = xpathHelper.GetSmallXpath(ele[0]);
                var xresult  = geckoWebBrowser.DomDocument.EvaluateXPath(xpathTxt);
                var nodes    = xresult.GetNodes();
                var elements = nodes.Select(x => x as GeckoElement).ToArray();
                //foreach (GeckoElement item in elements)
                //{
                //    geckoElementList.Add(item);
                //}
                geckoHtmlElementList = XpathHelper.FindHtmlTxt(true, elements);
            }
            else
            {
                //foreach (GeckoElement item in ele)
                //{
                //    geckoElementList.Add(item);
                //}

                geckoHtmlElementList = XpathHelper.FindHtmlTxt(true, ele);
            }

            foreach (GeckoHtmlElement element in geckoHtmlElementList)
            {
                //if (dgv.Rows.Count > 1)
                //{
                //    for (int i = 0 ; i < dgv.Rows.Count ; i++)
                //    {
                //        GeckoHtmlElement ghe = (GeckoHtmlElement)dgv.Rows[i].Cells[dgv.Rows[0].Cells.Count - 1].Value;
                //        if (ghe.Equals(element))
                //        {
                //            continue;
                //        }
                //    }
                //}


                DataGridViewRow row = new DataGridViewRow();
                //文本
                DataGridViewTextBoxCell fieldsNameCell = new DataGridViewTextBoxCell();
                fieldsNameCell.Value = "字段" + (count++);
                row.Cells.Add(fieldsNameCell);

                DataGridViewTextBoxCell fieldsContentCell = new DataGridViewTextBoxCell();
                fieldsContentCell.Value = element.TextContent;
                row.Cells.Add(fieldsContentCell);

                //下拉框
                DataGridViewTextBoxCell fieldsTypeCell = new DataGridViewTextBoxCell();
                fieldsTypeCell.Value = "抓取文本";
                row.Cells.Add(fieldsTypeCell);

                DataGridViewImageCell deleteCell = new DataGridViewImageCell();
                deleteCell.Value = Image.FromFile(@"E:\Project\C#\SimpleCrawlProject\SimpleCrawlApp\Resources\1108658.png");
                row.Cells.Add(deleteCell);

                //隐藏浏览器句柄
                DataGridViewTextBoxCell visibleGeckofxElementCell = new DataGridViewTextBoxCell();
                visibleGeckofxElementCell.Value = element;
                row.Cells.Add(visibleGeckofxElementCell);

                //隐藏xpath
                DataGridViewTextBoxCell visibleGeckofxXpathCell = new DataGridViewTextBoxCell();
                visibleGeckofxXpathCell.Value = xpathHelper.GetSmallXpath(element);
                row.Cells.Add(visibleGeckofxXpathCell);

                //将元素插入datagridview控件中
                dgv.Rows.Add(row);
            }
        }