public static int ParsePegasus(string deparCountry, string arrCountry, DateTime startDate, DateTime endDate, string dCity, string aCity) { if (dCity.Length > 0) { InitPegasus(deparCountry, arrCountry, startDate, endDate, dCity, aCity); ChromeDr.getInstance().Close(); return(0); } ChromeDr chromeDr = ChromeDr.getInstance(); chromeDr.dataInitialized = false; chromeDr.Driver.Navigate().GoToUrl("https://pegast.ru/agency/pegasys/flights"); List <IWebElement> cities = chromeDr.Driver.FindElements(By.Name("departureCity"))[0].FindElements(By.TagName("option")).ToList(); cities.RemoveAt(0); var citiesName = (from city in cities select city.Text).ToList(); foreach (var city in citiesName) { chromeDr.dataInitialized = false; chromeDr.Driver.Navigate().GoToUrl("https://pegast.ru/agency/pegasys/flights"); InitPegasus(deparCountry, arrCountry, startDate, endDate, city, aCity); } chromeDr.Close(); return(0); }
public static void ReadICS() { ChromeDr chromeDr = ChromeDr.getInstance(); chromeDr.Driver.Navigate().GoToUrl("https://www.icstrvl.ru/flights/index.html"); List <string> href = (from item in chromeDr.Driver.FindElementsByClassName("countries_list") from hr in item.FindElements(By.TagName("a")) where !string.IsNullOrEmpty(hr.GetAttribute("href")) && hr.GetAttribute("href").Length > 7 let formated = hr.GetAttribute("href").Substring(5) select formated /*.Remove(formated.Length - 2)*/).Take(1).ToList(); List <Task> tasks = new List <Task>(); foreach (string item in href) { chromeDr.Driver.Navigate().GoToUrl("https" + item); List <IWebElement> tables = chromeDr.Driver.FindElementsByClassName("bordered").ToList(); if (!tables.Any()) { continue; } string Operator = "ICS Travel Group"; List <TourInfo> data = (from table in tables from row in table.FindElements(By.TagName("tr")) let column = row.FindElements(By.TagName("td")) where column.Any() && column.Count() > 9 select new TourInfo() { TourOperator = Operator, City = column[1].Text, Date = new CDate() { date = column[2].Text, departureTime = column[6].Text, arrivalTime = column[7].Text }, FlightNum = column[3].Text, FlightCompany = column[4].Text, DepartureAirport = column[8].Text, ArrivalAirport = column[9].Text }).ToList(); string filename = item.Split('/').Last() + ".json"; Directory.CreateDirectory(Environment.CurrentDirectory + "\\json"); File.WriteAllText(Environment.CurrentDirectory + "\\json\\" + filename, JsonConvert.SerializeObject(data, Formatting.Indented)); } chromeDr.Close(); }