Exemple #1
0
        /// <summary>
        /// 解析航线信息
        /// </summary>
        /// <param name="strContent">航线内容</param>
        /// <param name="regexInstance">正则实例</param>
        /// <returns></returns>
        public IList <RouteInformation> ParseHtmlCode(string strContent, IRegexExpression regexInstance)
        {
            if (string.IsNullOrEmpty(strContent) || regexInstance == null)
            {
                return(null);
            }

            CtripRegexExpression ctripRegex = (CtripRegexExpression)regexInstance;

            IList <string> valueList = RegexOperation.GetValuesByRegex(ctripRegex.GetSingleRowRegex(), strContent);

            IList <RouteInformation> routeInformationList = new List <RouteInformation>();
            RouteInformation         routeInformation;

            foreach (string strValue in valueList)
            {
                routeInformation = GetRouteInformation(strValue, ctripRegex);

                if (routeInformation != null)
                {
                    routeInformation.SeatList = GetSeatInformation(routeInformation, ctripRegex);

                    routeInformationList.Add(routeInformation);
                }
            }

            return(routeInformationList);
        }
Exemple #2
0
        private IList <Seat> GetSeatInformation(string strContent, VeryTripRegexExpression veryTripRegex)
        {
            IList <Seat> seatList = new List <Seat>();
            Seat         seat;

            IList <string> secondContentList = RegexOperation.GetValuesByRegex(veryTripRegex.GetSingleRowSecondRegex(), strContent);

            if (secondContentList == null)
            {
                return(seatList);
            }

            string strPrice = string.Empty;

            foreach (string strResult in secondContentList)
            {
                seat       = new Seat();
                seat.Cabin = RegexOperation.GetValueByRegex(veryTripRegex.GetCabinRegex(), strResult);

                strPrice = RegexOperation.GetValueByRegex(veryTripRegex.GetTicketPriceRegex(), strResult);
                if (!string.IsNullOrEmpty(strPrice))
                {
                    seat.Price = double.Parse(strPrice);
                }

                seat.Count = 9;

                seat.SubCanbin = RegexOperation.GetValueByRegex(veryTripRegex.GetSubCanbin(), strResult);

                seatList.Add(seat);
            }

            return(seatList);
        }
Exemple #3
0
        private IList <Seat> GetSeatInformation(RouteInformation routeInformation, CtripRegexExpression ctripRegex)
        {
            IList <Seat> seatList = new List <Seat>();
            Seat         seat;

            string strUrl = GetUrl(routeInformation.OriginalAirport, routeInformation.DestinationAirport, routeInformation.DepartureTime, routeInformation.FlightNO);

            IList <string> resultList = RegexOperation.GetValuesByRegex(string.Format(ctripRegex.GetAllCabinInfomation(), routeInformation.FlightNO.Trim()), DownHtmlSource(strUrl));

            if (resultList == null)
            {
                return(seatList);
            }

            string strPrice = string.Empty;

            foreach (string strResult in resultList)
            {
                seat       = new Seat();
                seat.Cabin = RegexOperation.GetValueByRegex(ctripRegex.GetOtherCanbin(), strResult);

                strPrice = RegexOperation.GetValueByRegex(ctripRegex.GetOtherCanbinPrice(), strResult);
                if (!string.IsNullOrEmpty(strPrice))
                {
                    seat.Price = double.Parse(strPrice);
                }

                seat.Count = 9;

                seatList.Add(seat);
            }

            return(seatList);
        }
Exemple #4
0
        /// <summary>
        /// 解析航线信息
        /// </summary>
        /// <param name="strContent">航线内容</param>
        /// <param name="regexInstance">正则实例</param>
        /// <returns></returns>
        public IList <RouteInformation> ParseHtmlCode(string strContent, IRegexExpression regexInstance)
        {
            if (string.IsNullOrEmpty(strContent) || regexInstance == null)
            {
                return(null);
            }

            ElongRegexEpression etripRegex = (ElongRegexEpression)regexInstance;
            //StringReader sr = new StringReader(strContent);
            IList <string> valueList = RegexOperation.GetValuesByRegex(etripRegex.GetSingleRowRegex(), strContent);

            IList <RouteInformation> ElongrouteInformationList = new List <RouteInformation>();
            RouteInformation         elongrouteInformation;

            foreach (string strValue in valueList)
            {
                elongrouteInformation = GetElongRouteInformation(strValue.ToString(), etripRegex);

                if (elongrouteInformation != null)
                {
                    ElongrouteInformationList.Add(elongrouteInformation);
                }
            }

            return(ElongrouteInformationList);
        }
Exemple #5
0
        private IList <string> GetPageUrl(string strContent, VeryTripRegexExpression veryRegexInstance)
        {
            IList <string> pageUrlList = new List <string>();

            string strPages = RegexOperation.GetValueByRegex(veryRegexInstance.GetPageFragmentRegex(), strContent);

            if (string.IsNullOrEmpty(strPages))
            {
                return(pageUrlList);
            }


            IList <string> suffixUrlList = RegexOperation.GetValuesByRegex(veryRegexInstance.GetPageLinkRegex(), strPages);

            foreach (string strSuffixUrl in suffixUrlList)
            {
                pageUrlList.Add(GetPrefixUrl() + strSuffixUrl);
            }

            return(pageUrlList);
        }
Exemple #6
0
        private List <RouteInformation> GetCurrentPageRoute(string strContent, VeryTripRegexExpression veryTripRegex)
        {
            IList <string> valueList = RegexOperation.GetValuesByRegex(veryTripRegex.GetSingleRowRegex(), strContent);

            List <RouteInformation> routeInformationList = new List <RouteInformation>();
            RouteInformation        routeInformation;

            foreach (string strValue in valueList)
            {
                routeInformation = GetRouteInformation(strValue, veryTripRegex);

                if (routeInformation != null)
                {
                    routeInformation.SeatList = GetSeatInformation(strValue, veryTripRegex);

                    routeInformationList.Add(routeInformation);
                }
            }

            return(routeInformationList);
        }
Exemple #7
0
        private RouteInformation GetRouteInformation(string strContent, CtripRegexExpression ctripRegex)
        {
            if (string.IsNullOrEmpty(strContent))
            {
                return(null);
            }

            string strTbodyData = RegexOperation.GetValueByRegex(ctripRegex.GetTbodyDataRegex(), strContent);

            if (string.IsNullOrEmpty(strTbodyData))
            {
                return(null);
            }

            RouteInformation routeInformation = new RouteInformation();
            IList <string>   valueList;

            valueList = RegexOperation.GetValuesByRegex(ctripRegex.GetCityRegex(), strContent);
            if (valueList != null && valueList.Count == 2)
            {
                routeInformation.OriginalAirport    = valueList[0];
                routeInformation.DestinationAirport = valueList[1];
            }

            valueList = RegexOperation.GetValuesByRegex(ctripRegex.GetDateRegex(), strContent);
            if (valueList != null && valueList.Count == 2)
            {
                if (!string.IsNullOrEmpty(valueList[0]))
                {
                    routeInformation.DepartureTime = DateTime.Parse(valueList[0]);
                }

                if (!string.IsNullOrEmpty(valueList[1]))
                {
                    routeInformation.ArriveTime = DateTime.Parse(valueList[1]);
                }
            }

            routeInformation.AirDate = routeInformation.DepartureTime;

            string strDiscount = RegexOperation.GetValueByRegex(ctripRegex.GetDiscountRegex(), strTbodyData);

            if (!string.IsNullOrEmpty(strDiscount))
            {
                routeInformation.Discount = double.Parse(strDiscount);
            }

            string strTicketPrice = RegexOperation.GetValueByRegex(ctripRegex.GetTicketPriceRegex(), strTbodyData);

            if (!string.IsNullOrEmpty(strTicketPrice))
            {
                routeInformation.TicketPrice = double.Parse(strTicketPrice);
            }

            routeInformation.Meal    = RegexOperation.GetValueByRegex(ctripRegex.GetMealRegex(), strTbodyData);
            routeInformation.AirLine = RegexOperation.GetValueByRegex(ctripRegex.GetAirLineRegex(), strTbodyData);

            routeInformation.ChangeRule     = RegexOperation.GetValueByRegex(ctripRegex.GetChangeRuleRegex(), strContent);
            routeInformation.FlightInterval = RegexOperation.GetValueByRegex(ctripRegex.GetFlightIntervalRegex(), strContent);
            routeInformation.FlightNO       = RegexOperation.GetValueByRegex(ctripRegex.GetFlightNORegex(), strContent);
            routeInformation.FlightType     = RegexOperation.GetValueByRegex(ctripRegex.GetFlightTypeRegex(), strContent);
            routeInformation.ChangeRule     = RegexOperation.GetValueByRegex(ctripRegex.GetChangeRuleRegex(), strContent);
            routeInformation.Cabin          = RegexOperation.GetValueByRegex(ctripRegex.GetCabinRegex(), strContent);


            string strYprice = RegexOperation.GetValueByRegex(ctripRegex.GetYpriceRegex(), strContent);

            if (!string.IsNullOrEmpty(strYprice))
            {
                routeInformation.Yprice = double.Parse(strYprice);
            }

            string strAirportFuelTax = RegexOperation.GetValueByRegex(ctripRegex.GetAirportFuelRegex(), strContent);

            if (!string.IsNullOrEmpty(strAirportFuelTax))
            {
                string[] strDatas = strAirportFuelTax.Split('+');

                if (!string.IsNullOrEmpty(strDatas[0]))
                {
                    routeInformation.AirportTax = double.Parse(strDatas[0]);
                }

                if (!string.IsNullOrEmpty(strDatas[1]))
                {
                    routeInformation.FuelTax = double.Parse(strDatas[1]);
                }
            }

            return(routeInformation);
        }
Exemple #8
0
        /// <summary>
        /// 获取艺龙航线信息
        /// </summary>
        /// <param name="strContent"></param>
        /// <param name="etripRegex"></param>
        /// <returns></returns>
        private RouteInformation GetElongRouteInformation(string strContent, ElongRegexEpression etripRegex)
        {
            if (string.IsNullOrEmpty(strContent))
            {
                return(null);
            }
            string strRule  = RegexOperation.GetValueByRegex(etripRegex.GetRuleData(), strContent);
            string strTable = RegexOperation.GetValueByRegex(etripRegex.GetSingleRowRegex(), strContent);

            if (string.IsNullOrEmpty(strTable))
            {
                return(null);
            }
            string airline = RegexOperation.GetValueByRegex(etripRegex.GetAirLineRegex(), strContent);

            if (string.IsNullOrEmpty(airline))
            {
                return(null);
            }

            RouteInformation elongrouteInformation = new RouteInformation();
            IList <string>   valueList;

            //出发城市、到大城市
            valueList = RegexOperation.GetValuesByRegex(etripRegex.GetCityRegex(), strContent);
            if (valueList != null && valueList.Count == 2)
            {
                elongrouteInformation.OriginalAirport    = valueList[0];
                elongrouteInformation.DestinationAirport = valueList[1];
            }


            //出发城市
            //elongrouteInformation.OriginalAirport = RegexOperation.GetValuesByRegex(etripRegex.GetDepartureCityRegex(), strContent).ToString();
            //到达城市
            // elongrouteInformation.DestinationAirport = RegexOperation.GetValuesByRegex(etripRegex.GetArrivalCityRegex(), strContent).ToString();
            //航空公司
            elongrouteInformation.AirLine = RegexOperation.GetValueByRegex(etripRegex.GetAirLineRegex(), strTable).ToString();
            //航班号
            elongrouteInformation.FlightNO = RegexOperation.GetValueByRegex(etripRegex.GetFlightNORegex(), strContent).ToString();
            //舱位
            elongrouteInformation.Cabin = RegexOperation.GetValueByRegex(etripRegex.GetCabinRegex(), strContent).ToString();
            //机型
            elongrouteInformation.FlightType = RegexOperation.GetValueByRegex(etripRegex.GetFlightTypeRegex(), strRule).ToString();
            //退改
            elongrouteInformation.ChangeRule = RegexOperation.GetValueByRegex(etripRegex.GetChangeRuleRegex(), strContent).ToString();
            //折扣
            elongrouteInformation.Ediscount = RegexOperation.GetValueByRegex(etripRegex.GetDiscountRegex(), strContent).ToString();

            //税费
            string eAirportFuel = RegexOperation.GetValueByRegex(etripRegex.GetEAirportFuelRegex(), strTable).ToString();

            if (!string.IsNullOrEmpty(eAirportFuel))
            {
                elongrouteInformation.Eairportfuel = double.Parse(eAirportFuel);
            }
            //机建
            string airPort = RegexOperation.GetValueByRegex(etripRegex.GetAirportRegex(), strContent).ToString();

            if (!string.IsNullOrEmpty(airPort))
            {
                elongrouteInformation.AirportTax = double.Parse(airPort);
            }
            //燃油
            string fuel = RegexOperation.GetValueByRegex(etripRegex.GetFuelRegex(), strContent).ToString();

            if (!string.IsNullOrEmpty(fuel))
            {
                elongrouteInformation.FuelTax = double.Parse(fuel);
            }
            //票价
            string ticketPrice = RegexOperation.GetValueByRegex(etripRegex.GetTicketPriceRegex(), strContent).ToString();

            if (!string.IsNullOrEmpty(ticketPrice))
            {
                elongrouteInformation.TicketPrice = double.Parse(ticketPrice);
            }

            string yearmonthday = RegexOperation.GetValueByRegex(etripRegex.GetYearMonthDay(), strRule).ToString();

            //出发时间
            string departureTime = RegexOperation.GetValueByRegex(etripRegex.GetDepartureTimeRegex(), strContent).ToString();
            string yd            = yearmonthday + " " + departureTime;

            if (!string.IsNullOrEmpty(departureTime))
            {
                elongrouteInformation.DepartureTime = DateTime.Parse(yd);
            }
            //到达时间
            string arrivalTime = RegexOperation.GetValueByRegex(etripRegex.GetArrivalTimeRegex(), strContent).ToString();
            string ya          = yearmonthday + " " + arrivalTime;

            if (!string.IsNullOrEmpty(arrivalTime))
            {
                elongrouteInformation.ArriveTime = DateTime.Parse(ya);
            }

            return(elongrouteInformation);
        }