private void button1_Click(object sender, EventArgs e) { try { string name = ListCItyUrl.SingleOrDefault(a => a.Value == GetUrl()).Key; Log.FileDelete(name); Log.Datalogger("" + "," + "楼盘" + "," + "开盘" + "," + "价格" + "," + "单位" + "," + "电话" + "," + "片区" + "," + "地址" + "," + "开发商" + "," + "交通情况" + "," + "开盘时间" + "," + "入住时间" + "," + "更新时间" + "," + "物业情况", name); CItyhouseList.Clear(); beginSearch(); } catch (Exception ex) { Log.logger(ex.ToString()); MessageBox.Show("button1_Click" + ex.ToString()); } }
private void GetOneUrlandnagative() { try { //保存文件 string name = ListCItyUrl.SingleOrDefault(a => a.Value == GetUrl()).Key; List <House> housList = CItyhouseList.Where(a => a.IsSearch == false).OrderBy(a => a.ID).ToList(); ShowLoadddingMsg(housList.Count + "/" + CItyhouseList.Count); if (housList.Count > 0) { House hous = housList[0]; if (hous.urll.Length > 0) { this.Browser.Navigate(hous.urll); hous.IsSearch = true; } } } catch (Exception ex) { Log.logger(ex.Message + ex.StackTrace); } }
void Browser_DocumentCompleted_xiangxi(object sender, EventArgs e) { GeckoWebBrowser br = sender as GeckoWebBrowser; if (br.Url.ToString() == "about:blank") { GetOneUrlandnagative(); return; } System.GC.Collect(); try { ShowClickMsg("开始加载每个楼盘的数据 " + br.Url.ToString()); foreach (Skybound.Gecko.GeckoElement a in br.Document.Links) { if ( a.Parent != null && a.Parent.TagName != null && a.Parent.TagName.ToLower() == "li" && a.Parent.Parent != null && a.Parent.Parent.TagName != null && a.Parent.Parent.TagName.ToLower() == "ul" && a.Parent.Parent.Parent != null && a.Parent.Parent.Parent.ClassName != null && a.Parent.Parent.Parent.ClassName == "blockLA" && a.Parent.Parent.Parent.Parent != null && a.Parent.Parent.Parent.Parent.ClassName != null && a.Parent.Parent.Parent.Parent.ClassName == "l" && a.Parent.Parent.Parent.Parent.Parent != null && a.Parent.Parent.Parent.Parent.Parent.ClassName != null && a.Parent.Parent.Parent.Parent.Parent.ClassName == "area" && a.Parent.Parent.Parent.Parent.Parent.Id == "contentB" ) { House house = CItyhouseList.Where(item => item.urll == br.Url.ToString()).ToList()[0]; if (house != null) { house.IsSearch = true; } else { GetOneUrlandnagative(); return; } if (house != null) { Skybound.Gecko.GeckoElement divinfoo = (Skybound.Gecko.GeckoElement)a.Parent.Parent.Parent.Parent.Parent; Skybound.Gecko.GeckoNode divclass111 = (Skybound.Gecko.GeckoNode)divinfoo.ChildNodes[1]; Skybound.Gecko.GeckoNode divblockaaa = (Skybound.Gecko.GeckoNode)divclass111.ChildNodes[1]; Skybound.Gecko.GeckoNode ulll1 = (Skybound.Gecko.GeckoNode)divblockaaa.ChildNodes[1]; house.updateTime = ((Skybound.Gecko.GeckoNode)ulll1.ChildNodes[1]).ChildNodes[1].TextContent; house.AlongArea = ((Skybound.Gecko.GeckoNode)ulll1.ChildNodes[5]).TextContent.Replace("所属片区:", ""); Skybound.Gecko.GeckoNode divblockBBBB = (Skybound.Gecko.GeckoNode)divclass111.ChildNodes[3]; Skybound.Gecko.GeckoNode ulllBBBB = (Skybound.Gecko.GeckoNode)divblockBBBB.ChildNodes[1]; house.Jiaotong = ((Skybound.Gecko.GeckoNode)ulllBBBB.ChildNodes[1]).TextContent.Replace("周围交通:", ""); house.opentime = ((Skybound.Gecko.GeckoNode)ulllBBBB.ChildNodes[3]).TextContent.Replace("开盘时间:", ""); house.LiveIntime = ((Skybound.Gecko.GeckoNode)ulllBBBB.ChildNodes[5]).TextContent.Replace("入住时间:", ""); } string name = ListCItyUrl.SingleOrDefault(item => item.Value == GetUrl()).Key; Log.Datalogger(house.ID + "," + GetRightString(house.Name.Replace(",", "、")) + "," + GetRightString(house.HouseType.Replace(",", "、")) + "," + house.Price + "," + GetRightString(house.Danwei) + "," + GetRightString(house.phones.Replace(",", "、")) + "," + GetRightString(house.AlongArea.Replace(",", "、")) + "," + house.address.Replace(",", "、").Replace("查看地图", "") + "," + GetRightString(house.Kaifangshang.Replace(",", "、")) + "," + GetRightString(house.Jiaotong.Replace(",", "、")) + "," + GetRightString(house.opentime.Replace(",", "、")) + "," + GetRightString(house.LiveIntime.Replace(",", "、")) + "," + GetRightString(house.updateTime.Replace(",", "、")) + "," + GetRightString(house.wuyeleixing.Replace(",", "、")), name); break; } } GetOneUrlandnagative(); } catch (Exception ex) { Log.logger(ex.Message + ex.StackTrace); GetOneUrlandnagative(); } }
void Browser_DocumentCompleted(object sender, EventArgs e) { GeckoWebBrowser br = sender as GeckoWebBrowser; //加载成功开始分析。 if (br.Url.ToString() == "about:blank") { return; } ShowClickMsg("加载成功开始分析" + br.Url.ToString()); Log.logger("加载成功开始分析" + br.Url.ToString()); int CountLoupan = 0; foreach (Skybound.Gecko.GeckoElement a in br.Document.Links) { if (a.Parent != null && a.Parent.Parent != null && a.Parent.Parent.ClassName != null && a.Parent.Parent.ClassName == "t" && a.Parent.Parent.Parent != null && a.Parent.Parent.Parent.ClassName != null && a.Parent.Parent.Parent.ClassName == "h3 clear" && a.Parent.Parent.Parent.Parent != null && a.Parent.Parent.Parent.Parent.ClassName != null && a.Parent.Parent.Parent.Parent.ClassName == "rinfo" ) { CountLoupan++; if (a.TextContent == null) { continue; } House hous = new House(); string price = a.Parent.Parent.Parent.ChildNodes[3].TextContent.Replace("\n\n\t\t\t \n\t\t\t ", ""); // price.Replace("元/平米", "").Replace("均价:", "").Replace(",", "").Trim() "起价:75万元/套" string if (price == " ") { hous.Price = 0; } else { //最高价:8,016万元/套 int priceint = 0; string trimprice = price.Replace(",", ""); if (price.IndexOf("元/平米") >= 0) { trimprice = price.Replace("元/平米", "").Replace("均价:", "").Replace(",", "").Replace("起价:", "").Replace("二手房参考价:", ""); int.TryParse(trimprice, out priceint); hous.Price = priceint; hous.Danwei = "元/平米"; } if (price.IndexOf("万元/套") >= 0) { trimprice = price.Replace("万元/套", "").Replace("最高价:", "").Replace(",", "").Replace("起价:", ""); int.TryParse(trimprice, out priceint); hous.Price = priceint; hous.Danwei = "万元/套"; } } hous.Name = a.Parent.Parent.Parent.ChildNodes[1].ChildNodes[0].TextContent; Skybound.Gecko.GeckoElement isnew = (Skybound.Gecko.GeckoElement)a.Parent.Parent.ChildNodes[1]; hous.HouseType = isnew.TextContent; string[] sArray = Regex.Split(GetUrl(), "housemarket", RegexOptions.IgnoreCase); // 均价:12,800元/平米 hous.urll = sArray[0] + a.GetAttribute("href").TrimStart('/'); Skybound.Gecko.GeckoElement divadd = (Skybound.Gecko.GeckoElement)a.Parent.Parent.Parent.Parent; Skybound.Gecko.GeckoElement wuye = (Skybound.Gecko.GeckoElement)divadd.ChildNodes[3]; string wuyename = wuye.ChildNodes[1].TextContent; //物业类型:普通住宅 别墅 花园洋房 string phone = wuye.ChildNodes[3].TextContent.Replace("\n\t\t\t\t", ""); //电话:400-888-2200 转 13923 Skybound.Gecko.GeckoNode kaifangshang = (Skybound.Gecko.GeckoNode)divadd.ChildNodes[5]; string address = kaifangshang.TextContent; if (wuyename != null) { hous.wuyeleixing = wuyename.Replace("物业类型:", ""); } else { hous.wuyeleixing = "无"; } if (phone != null) { hous.phones = phone.Replace("电话:", ""); } else { hous.phones = "无"; } string[] kaifang_address = address.Split(new string[] { "查看地图" }, StringSplitOptions.RemoveEmptyEntries); if (kaifang_address.Length >= 2) { hous.Kaifangshang = kaifang_address[1].Replace("开 发 商:", ""); hous.address = kaifang_address[0].Replace("物业地址:", ""); } else { hous.Kaifangshang = address;//物业地址:大兴京开高速庞各庄出口南1000米查看地图\r\n开 发 商:北京富源盛达房地产开发有限公司 hous.address = "无法识别地址"; } if (hous.Danwei == null) { hous.Danwei = ""; } if (hous.wuyeleixing == null) { hous.wuyeleixing = ""; } if (hous.phones == null) { hous.phones = ""; } if (hous.Kaifangshang == null) { hous.Kaifangshang = ""; } ShowClickMsg(i + "_" + "楼盘:" + hous.Name.Trim() + ";" + hous.Price + " " + hous.Danwei.Trim() + ";" + hous.wuyeleixing.Trim() + ";" + hous.phones.Trim() + ";" + hous.Kaifangshang.Trim()); House house = CItyhouseList.SingleOrDefault(item => item.urll == hous.urll); if (house == null) { hous.ID = AllCItyCount; ShowLoadddingMsg(AllCItyCount.ToString()); CItyhouseList.Add(hous); AllCItyCount++; } } } i++; count++; string urll = GetUrl() + "index.php?page=" + i;// "http://sh.focus.cn/housemarket/house_search/index.php?page=" + i; ShowClickMsg(urll); string page = GetPage(); if (page == "") { page = "300"; } System.GC.Collect(); if (i < int.Parse(page) && CountLoupan > 0) { this.Browser.Navigate(urll); } else // if (CountLoupan == 0) //没有查找到新页面了。就可以查找二级页面了。 { this.Browser.DocumentCompleted -= new EventHandler(Browser_DocumentCompleted); this.Browser.DocumentCompleted += new EventHandler(Browser_DocumentCompleted_xiangxi); GetOneUrlandnagative(); } }