예제 #1
0
        public static List <BaseHouseInfo> GetHouseData(string groupID, string cityName, int pageIndex)
        {
            List <BaseHouseInfo> lstHouseInfo = new List <BaseHouseInfo>();
            var apiURL = $"https://api.douban.com/v2/group/{groupID}/topics?start={pageIndex * 50}";
            //LogHelper.Info($"url:{apiURL},groupID:{groupID}, city:{cityName}");
            var result = GetAPIResult(apiURL);

            if (string.IsNullOrEmpty(result))
            {
                return(lstHouseInfo);
            }
            var resultJObject = JsonConvert.DeserializeObject <JObject>(result);

            foreach (var topic in resultJObject["topics"])
            {
                var house = new BaseHouseInfo()
                {
                    HouseLocation    = topic["title"].ToString(),
                    HouseTitle       = topic["title"].ToString(),
                    HouseOnlineURL   = topic["share_url"].ToString(),
                    HouseText        = topic["content"].ToString(),
                    IsAnalyzed       = true,
                    Source           = ConstConfigurationName.Douban,
                    LocationCityName = cityName,
                    Status           = 1,
                    PubTime          = topic["created"].ToObject <DateTime>(),
                    DataCreateTime   = DateTime.Now,
                };
                lstHouseInfo.Add(house);
            }

            return(lstHouseInfo);
        }
예제 #2
0
        public static List <BaseHouseInfo> GetHouseData(int pageNum)
        {
            var result = getResultFromAPI(pageNum);

            List <BaseHouseInfo> houseList = new List <BaseHouseInfo>();
            var resultJObject = JsonConvert.DeserializeObject <JObject>(result);

            if (resultJObject == null || resultJObject["head"] == null || !resultJObject["head"]["success"].ToObject <Boolean>())
            {
                return(houseList);
            }
            foreach (var item in resultJObject["houseList"])
            {
                BaseHouseInfo houseInfo = new BaseHouseInfo();
                var           houseDesc = item["houseDescript"].ToObject <string>().Replace("😄", "");
                var           houseURL  = $"http://www.huzhumaifang.com/Renting/house_detail/id/{item["houseId"]}.html";
                houseInfo.HouseOnlineURL   = houseURL;
                houseInfo.HouseTitle       = houseDesc;
                houseInfo.HouseLocation    = houseDesc;
                houseInfo.HouseText        = item.ToString();
                houseInfo.HousePrice       = item["houseRentPrice"].ToObject <Int32>();
                houseInfo.DisPlayPrice     = item["houseRentPrice"].ToString();
                houseInfo.DataCreateTime   = DateTime.Now;
                houseInfo.LocationCityName = "上海";
                houseInfo.PubTime          = item["houseCreateTime"].ToObject <DateTime>();

                houseInfo.Source = ConstConfigurationName.HuZhuZuFang;
                houseList.Add(houseInfo);
            }
            return(houseList);
        }
        private static List <BaseHouseInfo> GetDataFromHMTL(string shortCutName, string cityName, string houseHTML)
        {
            List <BaseHouseInfo> houseList = new List <BaseHouseInfo>();

            if (string.IsNullOrEmpty(houseHTML))
            {
                return(houseList);
            }
            var htmlDoc  = htmlParser.Parse(houseHTML);
            var logrList = htmlDoc.QuerySelectorAll("li").Where(element => element.HasAttribute("logr"));

            if (!logrList.Any())
            {
                return(houseList);
            }
            foreach (var element in logrList)
            {
                var houseTitle    = element.QuerySelector("h2").TextContent;
                var houseInfoList = houseTitle.Split(' ');
                int.TryParse(element.QuerySelector("b").TextContent, out var housePrice);
                var onlineUrl = $"http://{shortCutName}.58.com" + element.QuerySelector("a").GetAttribute("href");
                var houseInfo = new BaseHouseInfo
                {
                    HouseTitle       = houseTitle,
                    HouseOnlineURL   = onlineUrl,
                    DisPlayPrice     = element.QuerySelector("b").TextContent,
                    HouseLocation    = new[] { "公寓", "青年社区" }.All(s => houseInfoList.Contains(s)) ? houseInfoList[0] : houseInfoList[1],
                    DataCreateTime   = DateTime.Now,
                    HousePrice       = housePrice,
                    HouseText        = houseTitle,
                    LocationCityName = cityName,
                    PubTime          = DateTime.Now
                };
                houseList.Add(houseInfo);
            }
            return(houseList);
        }