Ejemplo n.º 1
0
        private IEnumerable <HouseInfo> GetRoomListByIndex(string cnName, int index)
        {
            var url        = $"http://{cnName}.58.com/pinpaigongyu/pn/{index}";
            var htmlResult = HTTPHelper.GetHTMLByURL(url);
            var page       = new HtmlParser().Parse(htmlResult);

            return(page.QuerySelectorAll("li").Where(element => element.HasAttribute("logr")).Select(element =>
            {
                var houseTitle = element.QuerySelector("h2").TextContent;
                var houseInfoList = houseTitle.Split(' ');
                int housePrice = 0;
                int.TryParse(element.QuerySelector("b").TextContent, out housePrice);
                var markBGType = LocationMarkBGType.SelectColor(housePrice / 1000);

                return new HouseInfo
                {
                    HouseTitle = houseTitle,
                    HouseURL = $"http://{cnName}.58.com" + element.QuerySelector("a").GetAttribute("href"),
                    Money = element.QuerySelector("b").TextContent,
                    HouseLocation = new[] { "公寓", "青年社区" }.All(s => houseInfoList.Contains(s)) ? houseInfoList[0] : houseInfoList[1],
                    LocationMarkBG = markBGType,
                };
            }));
        }
Ejemplo n.º 2
0
        public IActionResult GetHouseInfo(string cityName, string source = "", int houseCount = 100,
                                          int intervalDay = 7, string keyword = "", bool refresh = false)
        {
            try
            {
                var houseList = houseDapper.SearchHouseInfo(cityName, source, houseCount, intervalDay, keyword, refresh);
                var rooms     = houseList.Select(house =>
                {
                    var markBGType = string.Empty;
                    int housePrice = (int)house.HousePrice;
                    if (housePrice > 0)
                    {
                        markBGType = LocationMarkBGType.SelectColor(housePrice / 1000);
                    }

                    return(new HouseInfo
                    {
                        ID = house.Id,
                        Source = house.Source,
                        Money = house.DisPlayPrice,
                        HouseURL = house.HouseOnlineURL,
                        HouseLocation = house.HouseLocation,
                        HouseTime = house.PubTime.ToString(),
                        HouseTitle = house.HouseTitle,
                        HousePrice = housePrice,
                        LocationMarkBG = markBGType,
                        DisplaySource = ConstConfigurationName.ConvertToDisPlayName(house.Source)
                    });
                });
                return(Json(new { IsSuccess = true, HouseInfos = rooms }));
            }
            catch (Exception ex)
            {
                return(Json(new { IsSuccess = false, error = ex.ToString() }));
            }
        }