예제 #1
0
파일: Program.cs 프로젝트: jiasw/House
            protected override void Handle(DotnetSpider.Core.Page page)
            {
                List <HouseInfo> list = new List <HouseInfo>();
                var HouseList         = page.Selectable.XPath(".//ul[@class='sellListContent']/li").Nodes();

                foreach (var HouseInfo in HouseList)
                {
                    HouseInfo house = new HouseInfo();

                    house.Title     = HouseInfo.XPath("./div[@class='info clear']/div[@class='title']/a").GetValue();
                    house.Community = HouseInfo.XPath("./div[@class='info clear']/div[@class='address']/div[@class='houseInfo']/a").GetValue();
                    house.Url       = HouseInfo.XPath("./a[@class='noresultRecommend img ']/@href").GetValue();
                    string Communitystr = HouseInfo.XPath("./div[@class='info clear']/div[@class='address']/div[@class='houseInfo']").GetValue(ValueOption.InnerText);

                    string flood = HouseInfo.XPath("./div[@class='info clear']/div[@class='flood']/div[@class='positionInfo']").GetValue(ValueOption.InnerText);
                    if (!string.IsNullOrEmpty(flood))
                    {
                        string[] ArrCommunity = flood.Split('-');
                        if (ArrCommunity.Length > 0)
                        {
                            //house.Area = ArrCommunity[0];
                            house.Location = ArrCommunity[1];
                        }
                    }
                    string followInfo = HouseInfo.XPath("./div[@class='info clear']/div[@class='followInfo']").GetValue(ValueOption.InnerText);
                    if (!string.IsNullOrEmpty(followInfo))
                    {
                        string[] ArrCommunity = followInfo.Split('/');
                        if (ArrCommunity.Length > 0)
                        {
                            house.WatchCount    = int.Parse(ArrCommunity[0].Substring(ArrCommunity[0].IndexOf("人") - 1, 1));
                            house.LeadShowCount = int.Parse(ArrCommunity[1].Substring(ArrCommunity[1].IndexOf("次") - 1, 1));
                        }
                    }


                    house.PriceCount = decimal.Parse(HouseInfo.XPath("./div[@class='info clear']/div[@class='priceInfo']/div[@class='totalPrice']/span").GetValue());
                    house.Price      = decimal.Parse(HouseInfo.XPath("./div[@class='info clear']/div[@class='priceInfo']/div[@class='unitPrice']/@data-price").GetValue());



                    list.Add(house);
                }
                page.AddResultItem("HouseList", list);
            }
예제 #2
0
파일: Program.cs 프로젝트: jiasw/House
            protected override void Handle(DotnetSpider.Core.Page page)
            {
                HouseInfo Model = new HouseInfo();

                Model.Url = page.Request.Url;
                var HouseInfo = page.Selectable.XPath(".//div[@class='m-content']/div[@class='box-l']").Nodes();

                foreach (var item in HouseInfo)
                {
                    //基本信息
                    var BaseInfo = item.XPath(".//*[@id='introduction']/div/div/div[1]/div[2]/ul/li").Nodes();
                    foreach (var baseinfoitem in BaseInfo)
                    {
                        string title = baseinfoitem.XPath(".//span").GetValue(ValueOption.InnerText);
                        if (title == "房屋户型")
                        {
                            //2室2厅1厨1卫
                            string roominfo = baseinfoitem.XPath("./text()").GetValue();
                            if (roominfo.IndexOf("室") > 0)
                            {
                                Model.RoomCount = int.Parse(roominfo.Substring(roominfo.IndexOf("室") - 1, 1));
                            }
                            if (roominfo.IndexOf("厅") > 0)
                            {
                                Model.SaloonCount = int.Parse(roominfo.Substring(roominfo.IndexOf("厅") - 1, 1));
                            }
                            if (roominfo.IndexOf("卫") > 0)
                            {
                                Model.BathRoomCount = int.Parse(roominfo.Substring(roominfo.IndexOf("卫") - 1, 1));
                            }
                        }
                        else
                        {
                            string subitemtext = baseinfoitem.XPath("./text()").GetValue().Trim();
                            if (title == "所在楼层")
                            {
                                Model.Storey = subitemtext;
                            }
                            else if (title == "建筑面积")
                            {
                                Model.HouseArea = subitemtext.Replace("㎡", "");
                            }
                            else if (title == "户型结构")
                            {
                                Model.Housestruct = subitemtext;
                            }
                            else if (title == "套内面积")
                            {
                                Model.HouseInsideArea = subitemtext;
                            }
                            else if (title == "建筑类型")
                            {
                                Model.Building = subitemtext;
                            }
                            else if (title == "房屋朝向")
                            {
                                Model.HouseDirection = subitemtext;
                            }
                            else if (title == "建筑结构")
                            {
                                Model.BuildingStruct = subitemtext;
                            }
                            else if (title == "装修情况")
                            {
                                Model.Ornamant = subitemtext;
                            }
                            else if (title == "梯户比例")
                            {
                                Model.LiftScale = subitemtext;
                            }
                            else if (title == "供暖方式")
                            {
                                Model.WramStyle = subitemtext;
                            }
                            else if (title == "配备电梯")
                            {
                                Model.Lift = subitemtext;
                            }
                            else if (title == "产权年限")
                            {
                                Model.PropertyTime = subitemtext.Replace("年", "");
                            }
                        }
                    }

                    var transactionInfo = item.XPath(".//*[@id='introduction']/div/div/div[2]/div[2]/ul/li").Nodes();
                    foreach (var tranitem in transactionInfo)
                    {
                        string title = tranitem.XPath(".//span").GetValue(ValueOption.InnerText);
                        string value = tranitem.XPath("./span[2]").GetValue(ValueOption.InnerText).Trim();
                        if (title == "挂牌时间")
                        {
                            Model.HangOutTime = value;
                        }
                        else if (title == "交易权属")
                        {
                            Model.Ownership = value;
                        }
                        else if (title == "上次交易")
                        {
                            Model.LastSale = value;
                        }
                        else if (title == "房屋用途")
                        {
                            Model.HouseUseto = value;
                        }
                        else if (title == "房屋年限")
                        {
                            Model.HouseTime = value;
                        }
                        else if (title == "产权所属")
                        {
                            Model.Owne = value;
                        }
                        else if (title == "抵押信息")
                        {
                            Model.Mortgage = value;
                        }
                        else if (title == "房本备件")
                        {
                            Model.HouseLicence = value;
                        }
                    }


                    #region 房源特色
                    //var house = item.XPath(".//div[1]/div[@class='introContent showbasemore']/div[@class='baseattribute clear']").Nodes();
                    //foreach (var houseitem in house)
                    //{
                    //    string title = houseitem.XPath(".//div[@class='name']").GetValue();
                    //    string value = houseitem.XPath("../div[@class='content']").GetValue();
                    //    if (title == "售房详情")
                    //    {
                    //        Model.HouseDetails = value;
                    //    }
                    //    else if (title == "税费解析")
                    //    {
                    //        Model.TaxDetails = value;
                    //    }
                    //    else if (title == "权属抵押")
                    //    {
                    //        Model.MortgageDetails = value;
                    //    }
                    //    else if (title == "装修描述")
                    //    {
                    //        Model.OrnamantDetails = value;
                    //    }
                    //    else if (title == "核心卖点")
                    //    {
                    //        Model.SalePoint = value;
                    //    }
                    //}

                    #endregion
                }

                Model.Area = page.Selectable.XPath(".//div[@class='aroundInfo']/div[@class='areaName']/span[@class='info']/a/text()").GetValue();

                page.AddResultItem("HouseInfo", Model);
            }