public async Task <HotelData> GetHotelHTMLAsync(BookingComMetaModel metaModel) { var result = new HotelData(); var paramModel = metaModel.ParamModel; IRequestBuilder Builder = new BookingComRequestBuilder(); var authModel = new BasicAuthenticationModel("", ""); var queryModel = new QueryModel(metaModel.searchUrl) { AuthModel = authModel, ParamModel = paramModel }; var resultHTML = await GetBookingHTMLSearchResult(queryModel); var linkExtractor = new BookingComLinkExtractService(); var url = linkExtractor.GetHotelUrl(resultHTML, metaModel.hotelId, metaModel.endpoint); //if url is empty then there is another middle page if (string.IsNullOrEmpty(url)) { var middleurl = linkExtractor.GetHotelUrl1(resultHTML, metaModel.hotelId, metaModel.endpoint); queryModel = new QueryModel(middleurl) { AuthModel = authModel, ParamModel = new ParameterModel() }; var tmpHTML = await GetBookingHTMLSearchResult(queryModel); url = linkExtractor.GetHotelUrl(tmpHTML, metaModel.hotelId, metaModel.endpoint); } if (string.IsNullOrEmpty(url)) { result.Error = "no url can be extracted"; } else { url = url.Substring(0, url.IndexOf("?")); queryModel = new QueryModel(url); queryModel.ParamModel = paramModel; var html = await GetBookingHTMLSearchResult(queryModel); var htmlDoc = AgilityParser.GetParser(html); var priceNode = htmlDoc.DocumentNode.SelectSingleNode("//div[@id='blockdisplay1']"); if (priceNode == null) { result.Msg = "We have no availability on our site for this property"; } else { result.PriceData = priceNode.OuterHtml; } } return(result); }
public string GetHotelUrl(string html, string hotelId, string endpoint) { var result = ""; var htmlDoc = AgilityParser.GetParser(html); var hit = false; foreach (HtmlNode link1 in htmlDoc.DocumentNode.SelectNodes("//a[@href]").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("hotel_name_link"))) { var tmpurl = link1.Attributes["href"].Value.ToLower(); if (tmpurl.Contains(hotelId)) { hit = true; } else { var hotelName = "Bo Hotel"; var tokens = hotelName.ToLower().Split().AsEnumerable().ToList(); if (!tokens.Any(x => !tmpurl.Contains(x))) { hit = true; } } if (hit) { HtmlAttribute att = link1.Attributes["href"]; foreach (var link in att.Value.Split(' ')) { result = link; break; } break; } } if (string.IsNullOrEmpty(result)) { return(""); } return(string.Concat(endpoint, result)); }