I am trying to get the most recent NWS radar images using c#. There are directories on the NWS website that contain a list of the most recent images. However, the files are named by the date uploaded, not in numerical order. They are generally uploaded every few minutes, but the exact amount of minutes can vary by as much as 5 minutes. To get the URLs of the images, I could write an XML parser to extract the URLs from the index page, however this seems over complicated for such a simple task. In addition, this index page is not an API, and if they might change something with the format that would screw up the XML parser. Is there some other way to get the URLs of the most recent images?
Asked
Active
Viewed 1,746 times
0
-
1Seems like they consider it stable enough [to document the structure](http://www.srh.noaa.gov/jetstream/doppler/ridge_download.htm) – fvu Oct 27 '12 at 17:58
-
Right, so go up by one directory and pick the _0.gif file. – Hans Passant Oct 27 '12 at 18:33
-
I want to get the most recent IMAGES, not just the _0.gif. – msbg Oct 27 '12 at 19:49
-
possible duplicate of [United States Weather Radar Data Feed or API?](http://stackoverflow.com/questions/3142918/united-states-weather-radar-data-feed-or-api) – Peter O. Oct 28 '12 at 03:22
1 Answers
1
An html is not always a valid Xml. But you can use use a real html parser like HtmlAgilityPack for this.
WebClient wc = new WebClient();
var page = wc.DownloadString("http://radar.weather.gov/ridge/RadarImg/NCR/OKX/?C=M;O=D");
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(page);
var imageLink = doc.DocumentNode.SelectNodes("//td/a[@href]")
.Select(a=>a.Attributes["href"].Value)
.OrderByDescending(a=>a)
.First();
--EDIT--
Forget about this answer and go that way United States Weather Radar Data Feed or API?
-
After reading the webpage fvu mentioned in his comment, this does appear to be the good solution. – msbg Oct 28 '12 at 15:14