void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { var document = new HtmlDocument(); document.LoadHtml(e.Result); var stations = document.DocumentNode.SelectNodes("//tr[@align='center']"); foreach (var stationHtml in stations) { if (stations.IndexOf(stationHtml) == 0) continue; var items = stationHtml.SelectNodes(".//td"); var station = new Station(); station.Km = items.ElementAt(0).InnerHtml; station.Name = items.ElementAt(1).ChildNodes[1].InnerHtml; station.Arrival = items.ElementAt(2).InnerHtml; station.StationTime = items.ElementAt(3).InnerHtml; station.Departure = items.ElementAt(4).InnerHtml; Stations.Add(station); } var webClient = new WebClient(); webClient.DownloadStringCompleted += webClient_DownloadStringCompleted2; webClient.DownloadStringAsync(new Uri(urlXml, UriKind.Absolute)); }
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { var document = new HtmlDocument(); document.LoadHtml(e.Result); var info = document.DocumentNode.SelectNodes("//td[@class='Ttl']"); if (info == null) { NoResultFoundView(); return; } var nodes = info.Nodes(); Number = nodes.Last().InnerHtml.Trim(); Type = nodes.First().InnerHtml.Trim(); var stations = document.DocumentNode.SelectNodes("//tr[@align='center']"); if (stations == null || stations.Count == 0) { NoResultFoundView(); return; } foreach (var stationHtml in stations) { if (stations.IndexOf(stationHtml) == 0) continue; var items = stationHtml.SelectNodes(".//td"); var station = new Station(); station.Km = items.ElementAt(0).InnerHtml; station.Name = items.ElementAt(1).ChildNodes[1].InnerHtml; station.Arrival = items.ElementAt(2).InnerHtml; station.StationTime = items.ElementAt(3).InnerHtml; station.Departure = items.ElementAt(4).InnerHtml; Stations.Add(station); } var webClient = new WebClient(); webClient.DownloadStringCompleted += webClient_DownloadStringCompleted2; webClient.DownloadStringAsync(new Uri(urlXml + Number, UriKind.Absolute)); }