private int GetListSum(int costFrom, int costTo, string cnName) { var url = $"http://{cnName}.58.com/pinpaigongyu/pn/{1}/?minprice={costFrom}_{costTo}"; var htmlResult = PinPaiGongYuHouseCrawler.GetHouseHTML(url); var dom = new HtmlParser().Parse(htmlResult); var countNode = dom.GetElementsByClassName("listsum").FirstOrDefault()?.QuerySelector("em"); return(Convert.ToInt32((countNode?.TextContent) ?? "0")); }
private IEnumerable <HouseInfo> GetRoomList(int costFrom, int costTo, string cnName, int index) { var url = $"http://{cnName}.58.com/pinpaigongyu/pn/{index}/?minprice={costFrom}_{costTo}"; var htmlResult = PinPaiGongYuHouseCrawler.GetHouseHTML(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(' '); 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] }; })); }