public void AddDestinationsForAirportsFromFlightsFromDotCom(AirportCollection airports, string startFrom = null)
 {
     TotalStopwatch.Restart();
     for (int i = 0; i < airports.Count; i++)
     {
         AirportStopwatch.Restart();
         Airport airport = airports[i];
         if (!startFrom.IsNullOrEmpty())
         {
             if (airport.IATA.Equals(startFrom))
             {
                 startFrom = null;
             }
             else
             {
                 LogProgressWhenCollectingDestinationAirports(i, airport, airports);
                 continue;
             }
         }
         Driver.Navigate().GoToUrl($"https://www.flightsfrom.com/{airport.IATA}/destinations");
         string          pageSource = Driver.PageSource;
         MatchCollection matches    = Regex.Matches(pageSource, @"<span class=""airport-font-midheader destination-search-item"">(.*?)\s+([A-Z][A-Z][A-Z])");
         foreach (Match match in matches)
         {
             string iata     = match.Groups[2].Value;
             string location = match.Groups[1].Value;
             airport.DestinationAirports.Add(new Airport(iata, location));
         }
         LogProgressWhenCollectingDestinationAirports(i, airport, airports);
     }
 }
        public Dictionary <string, string> GetAllAirportsFromFlightsFromDotCom()
        {
            Dictionary <string, string> airports = new Dictionary <string, string>();

            Driver.Navigate().GoToUrl("https://www.flightsfrom.com/");
            IWebElement searchField = GetElementWithId("search");

            searchField.Click();

            List <string> listOfRandommisedAirports = GetListOfRandomisedAirports();

            TotalStopwatch.Restart();
            for (int i = 0; i < listOfRandommisedAirports.Count; i++)
            {
                AirportStopwatch.Restart();
                string randomAirport = (string)listOfRandommisedAirports[i];
                searchField.Clear();
                searchField.SendKeys(randomAirport);
                string          pageSource = Driver.PageSource;
                MatchCollection matches    = Regex.Matches(pageSource, @"ng-scope"">\r\n\s+([A-Z][A-Z][A-Z])\r\n(.|\r\n)*?ng-scope"">\r\n\s+(.*?) <");
                while (matches.Count == 8 && matches[0].Groups[1].Value.Equals("VAR"))
                {
                    pageSource = Driver.PageSource;
                    matches    = Regex.Matches(pageSource, @"ng-scope"">\r\n\s+([A-Z][A-Z][A-Z])\r\n(.|\r\n)*?ng-scope"">\r\n\s+(.*?) <");
                }
                foreach (Match match in matches)
                {
                    string iata     = match.Groups[1].Value;
                    string location = match.Groups[3].Value;
                    if (!airports.ContainsKey(iata))
                    {
                        airports.Add(iata, location);
                    }
                }

                LogProgressWhenCollectionAllAirports(i, randomAirport, listOfRandommisedAirports, airports);
            }
            return(airports);
        }
Example #3
0
 /// <summary>
 /// 重启计时
 /// </summary>
 internal void ReStart()
 {
     TotalStopwatch.Restart();
 }