I'm reading this Wikipedia page -> http://en.wikipedia.org/wiki/List_of_postal_codes_in_Spain, a list of zip codes in Spain.
My goal is to get all zip codes from the section "Full codes" in webpage. For example i need to get this information (zip code - locality):
03000 to 03099 - Alicante 03189 - Villamartin 03201 to 03299 - Elche 03400 - Villena
In my code, I have difficult to get only li and a tags after the title "Full Codes".
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://en.wikipedia.org/wiki/List_of_postal_codes_in_Spain");
request.UserAgent = "Test wiki";
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string htmlText = reader.ReadToEnd();
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(htmlText);
if (doc.DocumentNode != null)
{
HtmlNodeCollection divs = doc.DocumentNode.SelectNodes("//li");
foreach (HtmlNode listElement in divs)
{
if (listElement.SelectNodes("//a[@href]").Count > 0)
{ // I do not get what I wish
foreach (HtmlNode listElement2 in listElement.SelectNodes("//a[@href]"))
{
string s = listElement2.Name;
string ss = listElement2.InnerText;
}
}
}
}