public RootForeign CreateXmlDocument(SearchInputService input) { try { string adress = "https://abacuswebstart.abacus.com.sg/thong-minh/flight-search-process.aspx"; CookieCollection c = crawlerHelper.getCookieCollection(adress, "POST", getPostdata(input)); adress = "https://abacuswebstart.abacus.com.sg/thong-minh/ajax-flight.aspx"; HtmlDocument d = crawlerHelper.getDocument(adress, "POST", getPostdata2(), c); d.DocumentNode.InnerHtml = d.DocumentNode.InnerHtml.Replace("<![CDATA[", " "); //tao doi tuong RootForeign rootf = new RootForeign(); rootf.Departure = input.DepartureCode; rootf.Arrival = input.ArrivalCode; rootf.Flights = new List<FlightForeign>(); HtmlNodeCollection nodeColection = d.DocumentNode.SelectNodes("//div[@class='wsFlightResult wsFlightResultBorder']"); int i = 0; foreach (HtmlNode node in nodeColection) { try { FlightForeign flight = new FlightForeign(); flight.Id = i; i++; flight.outBoundForeign = new OutInBoundForeign(); flight.inBoundForeign = new OutInBoundForeign(); flight.Source = AirLineName.abacus; HtmlNode nodeFlight = node.SelectSingleNode("div/div[2]"); HtmlNode nodeDepart = nodeFlight.SelectSingleNode("div[1]"); flight.outBoundForeign.Segments = getSegments(input.DepartTime, nodeDepart, flight.outBoundForeign); if (input.IsRoundTrip) { HtmlNode nodeReturn = nodeFlight.SelectSingleNode("div[3]"); flight.inBoundForeign.Segments = getSegments(input.ReturnTime, nodeReturn, flight.inBoundForeign); } //lay gia tong HtmlNode nodePrice = node.SelectSingleNode("div/div[1]/div[3]"); flight.Price = decimal.Parse(nodePrice.InnerText) * MoneyRate.MONEY_RATE; //lay gia chi tiet HtmlNode nodePriceDetail = node.SelectSingleNode("div/div[1]/div[5]/table"); getPriceDetail(input, nodePriceDetail, flight); rootf.Flights.Add(flight); } catch { } } ////ghi ra file xml //XmlSerializer serializer = new XmlSerializer(typeof(RootForeign)); //TextWriter writer1 = new StreamWriter(folderPath + "Abacus_"+input.SessionId+".xml"); //serializer.Serialize(writer1, rootf); //writer1.Close(); return rootf; } catch { return null; } }
private List<FlightForeign> getListFlights(bool IsRoundTrip) { List<FlightForeign> li = new List<FlightForeign>(); try { bool isRoundTrip = true; if (blocks[0].inBound == null || blocks[0].inBound.Items == null || blocks[0].inBound.Items.Count == 0) isRoundTrip = false; if (IsRoundTrip != isRoundTrip) return li; int id = 0; if (IsRoundTrip) { foreach (ItemTemp it in blocks[0].outBound.Items) { foreach (ItemTemp it1 in blocks[0].inBound.Items) { FlightForeign f = new FlightForeign(); f.Id = id; id++; f.Source = AirLineName.tiger; //chieu di OutInBoundForeign outBoundForeign = new OutInBoundForeign(); outBoundForeign.Segments = Convert2ListSegmentForeign(it.Segments); f.outBoundForeign = outBoundForeign; //chieu ve OutInBoundForeign inBoundForeign = new OutInBoundForeign(); inBoundForeign.Segments = Convert2ListSegmentForeign(it1.Segments); f.inBoundForeign = inBoundForeign; li.Add(f); f.PriceBaseOut = it.prices[0].price; f.PriceBaseIn = it1.prices[0].price; } } } else { foreach (ItemTemp it in blocks[0].outBound.Items) { FlightForeign f = new FlightForeign(); f.Id = id; id++; f.Source = AirLineName.tiger; //chieu di OutInBoundForeign outBoundForeign = new OutInBoundForeign(); outBoundForeign.Segments = Convert2ListSegmentForeign(it.Segments); f.outBoundForeign = outBoundForeign; f.PriceBaseOut = it.prices[0].price; li.Add(f); } } } catch { } return li; }
//lay gia chi tiet cua nguoi lon,tre em,tre so sinh va gan vao bien flight private void getPriceDetail(SearchInputService input, HtmlNode nodePrice, FlightForeign flight) { int indexPrice = 1; if (input.Adults > 0) { HtmlNode nodeAdult = nodePrice.SelectSingleNode("tr[" + indexPrice + "]/td[2]"); flight.PriceAdult = decimal.Parse(nodeAdult.InnerText) * MoneyRate.MONEY_RATE; indexPrice++; } if (input.Children > 0) { HtmlNode nodeChildren = nodePrice.SelectSingleNode("tr[" + indexPrice + "]/td[2]"); flight.PriceChild = decimal.Parse(nodeChildren.InnerText) * MoneyRate.MONEY_RATE; indexPrice++; } if (input.Inf > 0) { HtmlNode nodeChildren = nodePrice.SelectSingleNode("tr[" + indexPrice + "]/td[2]"); flight.PriceInfant = decimal.Parse(nodeChildren.InnerText) * MoneyRate.MONEY_RATE; } HtmlNode nodeTaxPrice = nodePrice.SelectSingleNode("tr[last()-1]/td[2]"); flight.TaxPrice = decimal.Parse(nodeTaxPrice.InnerText) * MoneyRate.MONEY_RATE; }