コード例 #1
0
        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;
            }
        }
コード例 #2
0
 public RootForeign Convert2RootForeign(bool IsRoundTrip)
 {
     RootForeign r = new RootForeign();
     r.Departure = Departure;
     r.Arrival = Arrival;
     r.Flights = getListFlights(IsRoundTrip);
     return r;
 }