public static void StartScrapeTask(TimeSpan saveTime, string url) { if (_scrapeTask != null) { _cancellationTokenSource.Cancel(); } _cancellationTokenSource = new CancellationTokenSource(); _scrapeTask = RunScrapeTask(url, saveTime, _cancellationTokenSource.Token); DnsService.Start(); }
public static void StartScrapeTask(TimeSpan saveTime, string url) { if (_scrapeTask != null) { _cancellationTokenSource.Cancel(); } _scrapeTimeToKeep = saveTime.TotalSeconds > 300 ? 1 : (int)Math.Round(300 / saveTime.TotalSeconds); _cancellationTokenSource = new CancellationTokenSource(); _scrapeTask = RunScrapeTask(url, saveTime, _cancellationTokenSource.Token); DnsService.Start(); }
public static List <TrafficStats> ScrapeData(string url) { string rawData = string.Empty; try { rawData = GetHtml(url); } catch { Console.Write("Initial scrape timed out, trying again. "); rawData = GetHtml(url); } var data = new HtmlDocument(); data.LoadHtml(rawData); var trafficStats = data.DocumentNode .Descendants("tr") .Select(x => x.Elements("td")) .Where(x => x.Count() == 7) .Select(x => new TrafficStats { Ip = x.ElementAt(0).InnerText, Hostname = DnsService.GetHostName(x.ElementAt(0).InnerText, x.ElementAt(1).InnerText), Mac = x.ElementAt(2).InnerText, In = Convert.ToInt64(x.ElementAt(3).InnerText.Replace(",", "")), Out = Convert.ToInt64(x.ElementAt(4).InnerText.Replace(",", "")), LastSeen = x.ElementAt(6).InnerText, Day = _currentHour }) .ToList(); return(trafficStats); }