public static void FillLbCounty(ListBox lb,string baseSite) { using (System.Net.WebClient wc = new System.Net.WebClient()) { string html = wc.DownloadString(baseSite+"state_link_page.html"); //Check if page is meant to contain archived caches Regex ar = new Regex(@"archived-GLX"); if (ar.IsMatch(html)) { //parse country/county name and link to glx, both terms separated by non-greedy match .*? //previous version: @"cachelink[^>]+href[^>]+\.html[^>]+>([^<]*)<.*?<a[^>]+href=""([^""]*\.glx)""", Regex rgc = new Regex( @"<tr(?:\n|.)*?<td.*?CacheList.*?(?:\n|.)*?/td>(?:\n|.)*?<td[^>]*>([^<]*)</td>(?:\n|.)*?<a[^>]*cachelink[^>]+href[^>]+\.html[^>]+>(?:\n|.)*?<a[^>]+href=""([^""]*\.glx)""" ,RegexOptions.Singleline); MatchCollection mc = rgc.Matches(html); foreach (Match m in mc) { //htmldecode translates html entities LbLink cl = new LbLink(m.Groups[2].Value, System.Net.WebUtility.HtmlDecode(m.Groups[1].Value)); lb.Items.Add(cl); } if (lb.Items.Count>0) { lb.SelectedIndex=0; } } else { System.Windows.Forms.MessageBox.Show("Sorry: The directory of archived Caches on xylanthrop.de is of unknown format."); } } }
public static void FillLbCounty(ListBox lb, string baseSite) { using (System.Net.WebClient wc = new System.Net.WebClient()) { string html = wc.DownloadString(baseSite + "state_link_page.html"); //Check if page is meant to contain archived caches Regex ar = new Regex(@"archived-GLX"); if (ar.IsMatch(html)) { //parse country/county name and link to glx, both terms separated by non-greedy match .*? //previous version: @"cachelink[^>]+href[^>]+\.html[^>]+>([^<]*)<.*?<a[^>]+href=""([^""]*\.glx)""", Regex rgc = new Regex( @"<tr(?:\n|.)*?<td.*?CacheList.*?(?:\n|.)*?/td>(?:\n|.)*?<td[^>]*>([^<]*)</td>(?:\n|.)*?<a[^>]*cachelink[^>]+href[^>]+\.html[^>]+>(?:\n|.)*?<a[^>]+href=""([^""]*\.glx)""" , RegexOptions.Singleline); MatchCollection mc = rgc.Matches(html); foreach (Match m in mc) { //htmldecode translates html entities LbLink cl = new LbLink(m.Groups[2].Value, System.Net.WebUtility.HtmlDecode(m.Groups[1].Value)); lb.Items.Add(cl); } if (lb.Items.Count > 0) { lb.SelectedIndex = 0; } } else { System.Windows.Forms.MessageBox.Show("Sorry: The directory of archived Caches on xylanthrop.de is of unknown format."); } } }