public GeckofxWebbrowerFrm(TaskInfoEntity taskInfoEntity, DataGridView dgv, GeckofxWebbrowerType geckofxWebbrowerType, string URL = null) { InitializeComponent(); this.taskInfoEntity = taskInfoEntity; this.dgv = dgv; this.geckofxWebbrowerType = geckofxWebbrowerType; this.URL = URL; }
private string URL; //要执行的URL链接 //通用 public GeckofxWebbrower(Control control, DataGridView dgv, TaskInfoEntity taskInfoEntity, GeckofxWebbrowerType geckofxType, string URL) { //GeckoPreferences.User["gfx.font_rendering.graphite.enabled"] = false; geckoWebBrowser = new GeckoWebBrowser(); geckoWebBrowser.Parent = control; geckoWebBrowser.Dock = DockStyle.Fill; this.taskInfoEntity = taskInfoEntity; this.control = control; this.dgv = dgv; this.geckofxType = geckofxType; // 浏览类型 ruleStyle = new RuleStyle(); xpathHelper = new XpathHelper(); this.URL = URL; init(); }
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); } } }