void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (e.Url != Document.Url) return; if (regUrl.IsMatch(e.Url.ToString())) { foreach (HtmlElement elLink in Document.GetElementsByTagName("a")) { try { string strLink = elLink.GetAttribute("href"); if (regLink.IsMatch(strLink)) { listLink.Add(new KeyValuePair<string, object>(strLink, elLink.InnerText)); } } catch { } } try { HtmlElement btnNext = Document.Body.Children[2].GetElementsByTagName("input")[2]; if (bool.Parse(btnNext.GetAttribute("disabled"))) this.NavToNext(); else { page++; this.Navigate("http://gtj.wuxi.gov.cn/BA13/D/04/index_" + page.ToString() + ".shtml"); } } catch { this.NavToNext(); } return; } Model_Ground mg = new Model_Ground("无锡"); //开始计算信息包括的字段 List<string> arrCol = new List<string>(); HtmlElement tRow = null; HtmlElement tRowSub = null; try { int subIndex = 0; foreach (HtmlElement td in Document.GetElementById("Zoom").GetElementsByTagName("td")) { try { string str = td.InnerText.Replace("\n","").Replace("\r","").Replace(" ","").Replace(" ","").Trim(); if (str == "编号" || str == "地块编号") { tRow = td.Parent; if (int.Parse(td.GetAttribute("rowspan")) > 1) tRowSub = tRow.NextSibling; break; } } catch { } } foreach (HtmlElement td in tRow.Children) { string str = td.InnerText.Replace("\n","").Replace("\r","").Replace(" ","").Replace(" ","").Trim(); str = regColNameFilter.Replace(str, ""); KeyValuePair<string, string> kvCol; try { kvCol = listColName.FindAll(delegate(KeyValuePair<string, string> kv) { return kv.Key == str; })[0]; arrCol.Add(kvCol.Value); } catch { if (!arrPlaning.Contains(str)) { arrCol.Add(""); continue; } } int colSpan = int.Parse(td.GetAttribute("colspan")); if (colSpan == 1||int.Parse(td.GetAttribute("rowspan"))>1) continue; for (int i = 0; i < colSpan; i++) { str = tRowSub.Children[i + subIndex].InnerText.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace(" ", "").Trim(); str = regColNameFilter.Replace(str, ""); try { kvCol = listColName.FindAll(delegate(KeyValuePair<string, string> kv) { return kv.Key == str; })[0]; arrCol.Add(kvCol.Value); } catch { arrCol.Add(""); continue; } } } } catch { this.NavToNext(); return; } //mg.SourceLink = linkCurrent.Key; mg.SourceLink = linkCurrent.Key; //开始计算挂牌日期 foreach (HtmlElement td in Document.GetElementsByTagName("td")) { if (td.InnerText!=null&&td.InnerText.Trim() == "公开日期") { try { mg.ListingDate = DateTime.Parse(td.NextSibling.InnerText); } catch { } break; } } //开始计算挂牌编号 Match mListingNum = regListingNum.Match(Document.Title); if (mListingNum.Success) { mg.ListingNum = mListingNum.Value; } //开始计算每条招拍挂信息 int[] arrRowSpan = new int[arrCol.Count]; try { Type type = typeof(Model_Ground); HtmlElement tr = (tRowSub == null ? tRow : tRowSub).NextSibling; while (tr!=null) { if (tr.Children.Count == 0) break; string strGroundNum = tr.Children[0].InnerText; if (strGroundNum == null) break; strGroundNum = strGroundNum.Replace("\r", "").Replace("\n", "").Replace(" ","").Replace(" ","").Trim(); Match mGroundNum = regGroundNum.Match(strGroundNum); if (!mGroundNum.Success) { tr = tr.NextSibling; continue; } mg.GroundNum = mGroundNum.Value; int offset = 0; string strImageLink = null; for (int i = 1; i < arrCol.Count; i++) { if (arrCol[i] == "" || arrCol[i] == null) continue; if (arrRowSpan[i] > 0) { offset++; arrRowSpan[i]--; continue; } if (arrCol[i] == "GroundName") { try { strImageLink = tr.Children[i - offset].GetElementsByTagName("a")[0].GetAttribute("href"); } catch { } } string strValue = tr.Children[i-offset].InnerText; if (strValue != null) { strValue = strValue.Replace("\n", "").Replace("\r", "").Trim(); } FieldInfo info = type.GetField(arrCol[i]); Type t = info.FieldType; int rowSpan = int.Parse(tr.Children[i-offset].GetAttribute("rowspan"))-1; if (rowSpan > 0) { arrRowSpan[i] = rowSpan; } try { if (t == typeof(int)) { info.SetValue(mg, int.Parse(strValue)); } else if (t == typeof(double)) { info.SetValue(mg, double.Parse(strValue)); } else if (t == typeof(DateTime)) { info.SetValue(mg, DateTime.Parse(strValue)); } else { info.SetValue(mg, strValue); } } catch { } } mg.GroundName = mg.GroundName.Split('.')[0]; mg.StartingPrice *= 10000; mg.BidBond *= 10000; mg.Save(); Model_Ground_File mgf = new Model_Ground_File(mg.CityId, mg.GroundNum); if (strImageLink != null && strImageLink != ""&&mgf.GroundId>0) { try { string[] tmp = strImageLink.Split('/'); string strFileName = mg.CityId + "_" + tmp[tmp.Length - 1]; if (!Fn.IsExistGroundFile(strFileName, FileType.Image)) { bool b = Fn.DownloadFile(strImageLink, strFileName, FileType.Image); if (b) { mgf.FileName = strFileName; mgf.FileTitle = "土地红线图"; mgf.FileType = FileType.Image; mgf.Save(); } } } catch { } } tr = tr.NextSibling; } } catch (Exception ex) { Program.MainForm.AddMessage("错误!无锡地块数据抓取错误。链接:" + mg.SourceLink + "。地块Id:" + mg.GroundNum + "。错误消息:" + ex.Message); } this.NavToNext(); }
void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (e.Url != Browser.Url) return; if (e.Url.ToString().StartsWith("http://www.ntgt.gov.cn/gtzygl/app/gpcrController/listGpcrBySx?")) { bool flag = false; foreach (HtmlElement el in Document.GetElementsByTagName("a")) { try { string url = el.GetAttribute("href").Trim(); if (!url.StartsWith("http://www.ntgt.gov.cn/gtzygl/app/gpcrController/getView0/")) continue; flag = true; string strGrdNum = el.Parent.Parent.FirstChild.InnerText.Trim(); if (Fn.GetDT_PgSQL("select * from ground_info where cityid='" + cityId + "' and groundnum=" + q + strGrdNum + q + " and clinchprice>0").Rows.Count > 0) continue; listLink.Add(new KeyValuePair<string, object>(url, strGrdNum)); } catch { } } if (flag) this.NavToNextPage(); else this.NavToNext(); return; } try { HtmlElement div = null; foreach (HtmlElement el in Document.GetElementsByTagName("p")) { if (el.InnerText == "基本情况") { div = el.NextSibling; break; } } Model_Ground mg = new Model_Ground("南通"); mg.GroundNum = this.linkCurrent.Value.ToString(); mg.SourceLink = this.linkCurrent.Key; bool flagSold = false; string strImageLink = null; foreach (HtmlElement p in div.Children) { if (p.TagName.ToLower() != "p") continue; string txt=null; try { txt = p.InnerText.Trim(); } catch { continue; } int index = txt.IndexOf(":"); if (index < 0) index = txt.IndexOf(":"); if (index < 0) continue; string name = txt.Substring(0, index); string val = null; try { val = txt.Substring(index + 1); } catch { } if (val == null || val.Trim() == "") continue; val = val.Trim(); #region 计算上市字段值 try { switch (name) { case "地块座落": mg.GLocation = val; break; case "用地性质": mg.GUsage = val; break; case "地块面积": mg.GArea = Convert.ToDouble(val.Replace("平方米", "")); break; case "起 挂 价": mg.StartingPrice = Convert.ToDouble(val.Replace("元/平方米", "").Trim()) * mg.GArea; break; case "容 积 率": mg.PlotRatio = val; break; case "建筑密度": mg.BuildingDensity = val; break; case "绿 化 率": mg.GreeningRate = val; break; case "开发程度": mg.DevelopLevel = val; break; case "备 注": mg.Remark = val; break; case "报价增幅": mg.IncreaseRate = val; break; case "起始时间": mg.ListingDate = Convert.ToDateTime(val); break; case "终止时间": mg.ClinchDate = Convert.ToDateTime(val); break; case "挂牌情况": if (val == "成交") flagSold = true; else mg.ClinchDate = Convert.ToDateTime("1900-01-01"); break; } } catch { } #endregion } try { strImageLink = div.Parent.FirstChild.Children[1].GetAttribute("src"); } catch { } if (flagSold) { div = div.GetElementsByTagName("div")[0]; mg.Buyer = div.Children[0].InnerText.Split(':')[1].Trim(); mg.ClinchPrice = Convert.ToDouble(div.Children[1].InnerText.Split(':')[1].Replace("元/平方米", "")) * mg.GArea; mg.Save(true, null); } else { mg.Save(); } Model_Ground_File mgf = new Model_Ground_File(mg.CityId, mg.GroundNum); if (strImageLink != null && strImageLink != "" && mgf.GroundId > 0) { try { string strFileName = mg.CityId + "_ground_" + mg.GroundNum+".jpg"; if (!Fn.IsExistGroundFile(strFileName, FileType.Image)) { bool b = Fn.DownloadFile(strImageLink, strFileName, FileType.Image); if (b) { mgf.FileName = strFileName; mgf.FileTitle = "土地位置图"; mgf.FileType = FileType.Image; mgf.Save(); } } } catch { } } } catch { } this.NavToNext(); }