public override List <RoomTypeEx> AnalysePriceHtml(string html, string param, out string info, params string[] paras) { info = ""; List <RoomTypeEx> list = new List <RoomTypeEx>(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); HtmlNodeCollection roomtypes = doc.DocumentNode.SelectNodes("//*[@id=\"sortByRoom\"]/div/ul/li"); var node = doc.GetElementbyId("sortByRoom"); //roomtypes = doc.DocumentNode.SelectNodes("//div[@class=\"itemTitleAndDesc\"]"); var raterooms = doc.DocumentNode.SelectNodes("//li[@class=\"rate\"]"); RoomTypeEx room = null; Regex regbreakfirst = new Regex("</span>(?<breakfirst>.*?)<span"); Regex regbedtype = new Regex("((?<beg>.*?))"); foreach (var item in raterooms) { room = new RoomTypeEx() { CreateTime = DateTime.Now }; room.Plat = this._plat; string srpId = item.SelectSingleNode("div[3]/form/input[@name=\"srpId\"]").Attributes["value"].Value; string roomCode = item.SelectSingleNode("div[3]/form/input[@name=\"roomCode\"]").Attributes["value"].Value; string travelAgentRate = item.SelectSingleNode("div[3]/form/input[@name=\"travelAgentRate\"]").Attributes["value"].Value; string accessibleFlag = item.SelectSingleNode("div[3]/form/input[@name=\"accessibleFlag\"]").Attributes["value"].Value; room.PlatformEx = new HiltenRoomEx() { roomCode = roomCode, srpId = srpId, accessibleFlag = accessibleFlag, travelAgentRate = travelAgentRate }; if (paras.Length > 0) { room.HotelId = paras[0]; } if (paras.Length > 1) { room.HotelName = paras[1]; } room.PlatformPrivete = false; room.Name = item.SelectSingleNode("div/div/strong/a").ChildNodes[0].InnerText.Trim().Replace("详情", ""); if (item.SelectSingleNode("div[2]/span").ChildNodes.Count != 5) { room.Price = Convert.ToInt32(item.SelectSingleNode("div[2]/span").InnerText.Trim().Replace("元人民币", "").Replace(",", "")); } else { room.Price = Convert.ToInt32(item.SelectSingleNode("div[2]/span/ins").InnerText.Trim().Replace("元人民币", "").Replace(",", "")); } try { var matbreakfirst = regbreakfirst.Match(item.SelectSingleNode("div/div/strong/a").InnerHtml); if (matbreakfirst.Success) { room.Breadfast = matbreakfirst.Groups["breakfirst"].Value.Trim(); room.Breadfast = room.Breadfast.Replace("提前预付", ""); } var matbedtype = regbedtype.Match(room.Name); if (matbedtype.Success) { room.BedType = matbedtype.Groups["beg"].Value; } var cancelnode = item.SelectSingleNode("div/div/span").InnerText.Trim(); if (cancelnode.Contains("不可")) { room.IsCancel = false; } else { room.IsCancel = true; } } catch (Exception ex) { info = ex.ToString(); continue; } list.Add(room); } return(list); }
public override List <RoomTypeEx> AnalysePriceHtml(string html, string param, out string info, params string[] paras) { info = ""; //List<CtripRoom> ctriproomlist = new List<CtripRoom>(); List <RoomTypeEx> list = new List <RoomTypeEx>(); CtripPriceHtml pricehtml = null; try { pricehtml = JsonConvert.DeserializeObject <CtripPriceHtml>(html); } catch (Exception ex) { info = ex.ToString(); } if (pricehtml == null) { return(list); } HtmlAgilityPack.HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pricehtml.html); var nodes = doc.DocumentNode.SelectNodes("//tr[@expand]"); var roomtypes = nodes.GroupBy(x => x.Attributes["brid"].Value); RoomTypeEx r = null; foreach (var item in roomtypes) { var roomtype = doc.DocumentNode.SelectSingleNode("//tr[@expand=\"\" and @class=\"\" and @ brid=\"" + item.Key + "\"]"); //if (roomtype == null) // continue; string roomtypename = ""; try { //roomtypename = roomtype.SelectNodes("td")[0].InnerText.Trim().Replace("\n", "").Replace("查看详情", "").Trim(); roomtypename = item.First().SelectSingleNode("td/a[2]").InnerText.Replace("\n", "").Replace("查看详情", "").Trim(); } catch (Exception ex) { info = ex.ToString(); } foreach (var i in item) { r = new RoomTypeEx(); //if (!i.InnerHtml.Contains("data-firstmap")) // continue; var tracvalue = i.SelectSingleNode("td[@class=\"col7\"]/div/a[@class=\"btns_base22 J_hotel_order\"]")?.Attributes["tracevalue"].Value; if (tracvalue != null) { r.PlatformEx = JsonConvert.DeserializeObject <CtripPricePolicy>(tracvalue); } if (i.SelectSingleNode("td/span[@class=\"room_type_name\"]").SelectSingleNode("span") != null) { r.PlatformPrivete = true; r.Name = r.PlatformEx?.GetProperty("agentname"); } int price = 0; try { //if (i.ChildNodes[1].Attributes.Contains("data-roomid")) // r.PolicyID = i.ChildNodes[1].Attributes["data-roomid"].Value; //else if (i.ChildNodes[3].Attributes.Contains("data-roomid")) // r.PolicyID = i.ChildNodes[3].Attributes["data-roomid"].Value; r.PolicyID = r.PlatformEx?.GetProperty("roomid"); } catch (Exception ex) { r.PolicyID = null; } r.BaseRoomID = item.Key; r.HotelId = param; r.Name = roomtypename; r.CreateTime = DateTime.Now; try { if ((i.SelectSingleNode("td/span[@class=\"room_policy\"]")).InnerText.Contains("不可取消")) { r.IsCancel = false; } else { r.IsCancel = true; } } catch (Exception ex) { } try { if (i.SelectSingleNode("td/div/a") != null) { bool isnum = Int32.TryParse(i.SelectSingleNode("td/div/a")?.Attributes["data-price"].Value, out price); if (!isnum) { continue; } r.Price = price; } else { continue; } } catch (Exception ex) { info = ex.ToString(); continue; } if (i.Equals(item.ToArray()[0])) { r.BedType = i.SelectNodes("td")[2].InnerText; r.Breadfast = i.SelectNodes("td")[3].InnerText; //bool isnum = Int32.TryParse(i.SelectSingleNode("td/div/a").Attributes["data-price"].Value, out price); //if (!isnum) // continue; //r.Price = price; } else { r.BedType = i.SelectNodes("td")[1].InnerText; r.Breadfast = i.SelectNodes("td")[2].InnerText; //bool isnum = Int32.TryParse(i.SelectSingleNode("td/div/a").Attributes["data-price"].Value, out price); //if (!isnum) // continue; //r.Price = price; } list.Add(r); } } return(list); }