/// <summary> /// 获取单个房源详情 /// </summary> /// <param name="tradeType">id</param> /// <param name="buildingType">1 住宅 2 别墅 3 商铺 4 写字楼 5 厂房</param> /// <param name="id">id</param> /// <param name="cookie">Cookie</param> /// <returns></returns> private static ImportedHouse GetHouseDetail(byte tradeType, int buildingType, string id, string cookie, DateTime date, Dictionary <int, string> communityList) { const int siteId = 1008; string html = string.Empty; try { WebProxy proxy = KuaiDaili.GetProxy(); html = HttpUtility.GetString(string.Format(detailApi, buildingType, id), GetHeaders(cookie), false, proxy); } catch (WebException ex) { return(null); } var doc = new HtmlDocument(); doc.LoadHtml(html); HtmlNode node = doc.DocumentNode; HtmlNode title_Node = node.SelectSingleNode("//input[@id='saleHouse-title']"); HtmlNode xiaoquId_Node = node.SelectSingleNode("//input[@id='cellCode']"); HtmlNode xiaoqu_Node = node.SelectSingleNode("//input[@id='cell']"); HtmlNode address_Node = node.SelectSingleNode("//input[@id='addr']"); HtmlNode area_Node = node.SelectSingleNode("//input[@id='houseArea']"); HtmlNode areaUsed_Node = node.SelectSingleNode("//input[@id='areaUsed']"); HtmlNode price_Node = node.SelectSingleNode("//input[@id='price']"); HtmlNode floor_Node = node.SelectSingleNode("//input[@id='saleHouse-basic-flooron']"); HtmlNode florrAll_Node = node.SelectSingleNode("//input[@id='saleHouse-basic-floorall']"); HtmlNode note_Node = node.SelectSingleNode("//textarea[@id='houseDescribe']"); HtmlNode yijuhua_Node = node.SelectSingleNode("//input[@id='saleHouse-tongcheng-tip']"); HtmlNode tags_Node = node.SelectSingleNode("//input[@id='saleHouse-house-tip']"); HtmlNode tese_Node = node.SelectSingleNode("//input[@id='saleHouse-eare-tip']"); //HtmlNode createTime_Node = node.SelectSingleNode("//input[@id='releaseTime']"); MatchCollection roomimageMatches = new Regex("createImgDiv\\('(.*?IMG_I.*?)'").Matches(html); MatchCollection outdoorimageMatches = new Regex("createImgDiv\\('(.*?IMG_O.*?)'").Matches(html); MatchCollection fangxingimageMatches = new Regex("createImgDiv\\('(.*?IMG_M.*?)'").Matches(html); string payType = new Regex("\\$\\(\"#payType\"\\)\\.val\\(\"(.*?)\"").Match(html).Groups[1].Value; string year = new Regex("\\$\\(\"#saleHouse-basic-year\"\\)\\.val\\('(.*?)'").Match(html).Groups[1].Value; string pointTo = new Regex("name=pointTo\\]\\[value='(.*?)'").Match(html).Groups[1].Value; string lookTime = new Regex("name=lookTime\\]\\[value='(.*?)'").Match(html).Groups[1].Value; string fitmentStatus = new Regex("name=fitmentStatus\\]\\[value='(.*?)'").Match(html).Groups[1].Value; string district = new Regex("\\$\\(\"#distrctSelect\"\\)\\.val\\('(\\d+)'").Match(html).Groups[1].Value; string area = new Regex("\\$\\(\"#areaSelect\"\\)\\.val\\('(\\d+)'").Match(html).Groups[1].Value; int districtId = PostDataHelper.RMappingAreaID(district, siteId, 592); string communityName = xiaoqu_Node.GetAttributeValue("value", ""); var community = PostDataHelper.RMappingCommunityModel(xiaoquId_Node.GetAttributeValue("value", ""), siteId); if (community == null) { return(null); } int communityId = community.CommunityID; int areaId = community.RegionID > 0?(int)community.RegionID:PostDataHelper.RMappingAreaID(area, siteId, districtId); var house = new ImportedHouse { HouseID = id, CommunityID = communityId, CommunityName = communityList != null && communityList.ContainsKey(communityId)?communityList[communityId]:communityName, CurFloor = Helper_Xms.shortParse(Helper_Xms.GetAttributeValue(floor_Node)), MaxFloor = Helper_Xms.shortParse(Helper_Xms.GetAttributeValue(florrAll_Node)), BuildArea = Helper_Xms.shortParse(Helper_Xms.GetAttributeValue(area_Node)), UsedArea = Helper_Xms.shortParse(Helper_Xms.GetAttributeValue(areaUsed_Node)), UsedYear = Helper_Xms.shortParse(year), Price = Helper_Xms.shortParse(Helper_Xms.GetAttributeValue(price_Node)), PriceUnit = tradeType == 1 ? "万" : "元/月", Address = Helper_Xms.GetAttributeValue(address_Node), Title = title_Node.GetAttributeValue("value", ""), Note = note_Node == null ? "" : note_Node.InnerHtml, YiJuHua = Helper_Xms.GetAttributeValue(yijuhua_Node), HouseLabel = Helper_Xms.GetAttributeValue(tags_Node), CellLabel = Helper_Xms.GetAttributeValue(tese_Node), Distrctid = districtId, CityID = community.CityID ?? 0, RegionID = areaId, BuildType = (byte)buildingType, FitmentStatus = fitmentStatus, PointTo = pointTo, PayType = payType, Status = 1, LookHouseTime = lookTime, TradeType = tradeType, roomImages = (from Match imageMatch in roomimageMatches select imageMatch.Groups[1].Value).ToArray(), outdoorImages = (from Match imageMatch in outdoorimageMatches select imageMatch.Groups[1].Value).ToArray(), fangxingImages = (from Match imageMatch in fangxingimageMatches select imageMatch.Groups[1].Value).ToArray(), PostTime = date }; switch (buildingType) { case 1: house = Helper_Xms.GetHouseInfo(html, house); break; case 2: house = Helper_Xms.GetVillaInfo(html, house); break; case 3: house = Helper_Xms.GetShopInfo(html, house); break; case 4: house = Helper_Xms.GetOfficeInfo(html, house); break; case 5: house = Helper_Xms.GetFactoryInfo(html, house); break; } return(house); }
/// <summary> /// 获取单个房源详情 /// </summary> /// <param name="tradeType">id</param> /// <param name="id">id</param> /// <param name="cookie">Cookie</param> /// <returns></returns> private static ImportedHouse GetHouseDetail(byte tradeType, string id, string cookie) { const int siteId = 1; string html = HttpUtility.GetString(string.Format(detailApi, id, tradeType), Helper_ZJB.GetHeaders(cookie)); var doc = new HtmlDocument(); doc.LoadHtml(html); HtmlNode node = doc.DocumentNode; HtmlNode title_Node = node.SelectSingleNode("//input[@id='ContentRight_txtT_HouseInfos_Address']"); HtmlNode xiaoqu_Node = node.SelectSingleNode("//input[@id='ContentRight_txtZoneName_1']"); HtmlNode address_Node = node.SelectSingleNode("//input[@id='ContentRight_Txt_AderssDesc']"); HtmlNode area_Node = node.SelectSingleNode("//input[@id='ContentRight_txtT_HouseInfos_BuildArea']"); HtmlNode areaUsed_Node = node.SelectSingleNode("//input[@id='ContentRight_txtT_HouseInfos_UsedArea']"); HtmlNode price_Node = node.SelectSingleNode("//input[@id='ContentRight_txtT_HouseInfos_Price']"); HtmlNode floor_Node = node.SelectSingleNode("//input[@id='ContentRight_txtT_HouseInfos_CurFloor']"); HtmlNode florrAll_Node = node.SelectSingleNode("//input[@id='ContentRight_txtT_HouseInfos_MaxFloor']"); HtmlNode note_Node = node.SelectSingleNode("//textarea[@id='ContentRight_txtT_HouseInfos_Note']"); HtmlNode year_Node = node.SelectSingleNode("//input[@id='ContentRight_txtUsedYear']"); HtmlNode pointTo_Node = node.SelectSingleNode( "//select[@id='ContentRight_ddlT_HouseInfos_PointTo']/option[@selected='selected']"); HtmlNode room_Node = node.SelectSingleNode("//select[@id='ContentRight_ddl_Room']/option[@selected='selected']"); HtmlNode hall_Node = node.SelectSingleNode("//select[@id='ContentRight_ddl_Hall']/option[@selected='selected']"); HtmlNode toilet_Node = node.SelectSingleNode("//select[@id='ContentRight_ddl_Toilet']/option[@selected='selected']"); HtmlNode balcony_Node = node.SelectSingleNode("//select[@id='ContentRight_ddl_Balcony']/option[@selected='selected']"); HtmlNode fitment_Node = node.SelectSingleNode("//input[@name='ctl00$ContentRight$rblT_HouseInfos_FitmentStauts' and checked='checked']"); HtmlNode buildType_Node = node.SelectSingleNode("//select[@id='ContentRight_ddlT_HouseInfos_BuildType']/option[@selected='selected']"); // HtmlNode pointTo_Node = node.SelectSingleNode("//select[@id='']/option[@selected='selected']"); // HtmlNode pointTo_Node = node.SelectSingleNode("//select[@id='']/option[@selected='selected']"); // HtmlNode note_Node = node.SelectSingleNode("//textarea[@id='"); // HtmlNode note_Node = node.SelectSingleNode("//textarea[@id='"); // HtmlNode note_Node = node.SelectSingleNode("//textarea[@id='"); // MatchCollection imageMatches = new Regex("createImgDiv\\('(.*?)'").Matches(html); // string payType = new Regex("\\$\\(\"#payType\"\\)\\.val\\(\"(.*?)\"").Match(html).Groups[1].Value; // string year = new Regex("\\$\\(\"#saleHouse-basic-year\"\\)\\.val\\('(.*?)'").Match(html).Groups[1].Value; // string pointTo = new Regex("name=pointTo\\]\\[value='(.*?)'").Match(html).Groups[1].Value; // string lookTime = new Regex("name=lookTime\\]\\[value='(.*?)'").Match(html).Groups[1].Value; // string fitmentStatus = new Regex("name=fitmentStatus\\]\\[value='(.*?)'").Match(html).Groups[1].Value; var basicEquip = node.SelectNodes("//span[@id='ContentRight_chklT_HouseInfos_BasicEquip']/input[@checked = 'checked']"); var equip_Nodes = node.SelectNodes("//span[@id='ContentRight_chklT_HouseInfos_AdvEquip']/input[@checked = 'checked']"); var otherEquip_Nodes = node.SelectNodes("//span[@id='ContentRight_chklT_HouseInfos_OverEquip']/input[@checked = 'checked']"); string equip = ""; if (basicEquip != null) { equip = basicEquip.Aggregate(equip, (current, equip_Node) => current + (equip_Node.NextSibling.InnerText + ",")); } if (equip_Nodes != null) { equip = equip_Nodes.Aggregate(equip, (current, equip_Node) => current + (equip_Node.NextSibling.InnerText + ",")); } if (otherEquip_Nodes != null) { equip = otherEquip_Nodes.Aggregate(equip, (current, equip_Node) => current + (equip_Node.NextSibling.InnerText + ",")); } string district = new Regex("change\\(\"(\\d+)\"").Match(html).Groups[1].Value; string area = new Regex("change\\(\"\\d+\", \"(\\d+)\"").Match(html).Groups[1].Value; int districtId = PostDataHelper.RMappingAreaID(district, siteId, 592); // int areaId = PostDataHelper.RMappingAreaID(area, siteId, districtId); var picMatches = Regex.Matches(html, "delpic.*?pos=(.*?)&.*?spath=(.*?)'"); string[] pics = (from Match picMatch in picMatches select picMatch.Groups[1].Value).ToArray(); // List<string> tmp = ; string communityName = xiaoqu_Node.GetAttributeValue("value", ""); var community = PostDataHelper.RMappingCommunityModel(communityName, siteId); int communityId = 0; if (community == null) { return(null); } communityId = community.CommunityID; if (communityId == 0) { return(null); } List <string> tmp1 = new List <string>(); List <string> tmp2 = new List <string>(); List <string> tmp3 = new List <string>(); int sum = 0; foreach (Match picMatch in picMatches) { sum++; string pos = Uri.UnescapeDataString(picMatch.Groups[1].Value); string pic = "http://img.ZJB.com/Upload/InfoImage" + Uri.UnescapeDataString(picMatch.Groups[2].Value); if (pos.Contains("型")) { tmp3.Add(pic); } else if (pos.Contains("外") || pos.Contains("区")) { tmp2.Add(pic); } else { tmp1.Add(pic); } } decimal con = 1; decimal buildAreaValue = shortParse(GetAttributeValue(area_Node)); decimal usedAreaValue = shortParse(GetAttributeValue(areaUsed_Node)); usedAreaValue = usedAreaValue == 0 ? (decimal)(buildAreaValue - con) : usedAreaValue; var house = new ImportedHouse { HouseID = id, CommunityID = communityId, CommunityName = communityName, CurFloor = intParse(GetAttributeValue(floor_Node)), MaxFloor = intParse(GetAttributeValue(florrAll_Node)), BuildArea = buildAreaValue, UsedArea = usedAreaValue, UsedYear = intParse(GetAttributeValue(year_Node)), Price = shortParse(GetAttributeValue(price_Node)), PriceUnit = tradeType == 1 ? "万" : "元/月", Address = GetAttributeValue(address_Node), Title = title_Node.GetAttributeValue("value", ""), Note = note_Node == null ? "" : System.Web.HttpUtility.HtmlDecode(note_Node.InnerHtml), // YiJuHua = GetAttributeValue(yijuhua_Node), // HouseLabel = GetAttributeValue(tags_Node), // CellLabel = GetAttributeValue(tese_Node), Distrctid = districtId, CityID = community.CityID ?? 0, RegionID = community.RegionID, BuildType = 1, // FitmentStatus = fitmentStatus, PointTo = GetFocus(GetAttributeValue(pointTo_Node)), // PayType = payType, Status = 1, // LookHouseTime = lookTime, TradeType = tradeType, // imageUrls = (from Match imageMatch in imageMatches select imageMatch.Groups[1].Value).ToArray(), Balcony = byteParse(GetAttributeValue(balcony_Node)), Toilet = byteParse(GetAttributeValue(toilet_Node)), // Kitchen = byteParse(GetAttributeValue)), Room = byteParse(GetAttributeValue(room_Node)), Hall = byteParse(GetAttributeValue(hall_Node)), FitmentStatus = GetAttributeValue(fitment_Node), roomImages = tmp1.ToArray(), outdoorImages = tmp2.ToArray(), fangxingImages = tmp3.ToArray(), PicNum = (byte)sum }; string buildType = buildType_Node.GetAttributeValue("value", ""); switch (buildType) { case "9": { house.villaInfo = new VillaInfo { BasicEquip = equip, AdvEquip = equip }; house.BuildType = 2; } break; case "3": { house.factoryInfo = new FactoryInfo { BasicEquip = equip }; house.BuildType = 5; } break; case "2": { house.officeInfo = new OfficeInfo { BasicEquip = equip }; house.BuildType = 4; } break; case "4": case "5": { house.shopInfo = new ShopInfo { BasicEquip = equip }; house.BuildType = 3; } break; default: house.houseInfo = new HouseInfo { BasicEquip = equip, AdvEquip = equip }; house.BuildType = 1; break; } return(house); }