I'm trying to get some element from a <select>
and <option>
element.
This is my code:
for(int td = 1; td <= 1; td++)
{
using (WebClient wc = new WebClient())
{
string pagina = wc.DownloadString("http://www.serebii.net/attackdex-xy/");
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(pagina);
string attacco;
//var prova = doc.DocumentNode.SelectSingleNode("/html/body/table[2]/tr[2]/td[2]/div[2]/table/tr/td[1]/form/select/option");
foreach (HtmlNode node in doc.DocumentNode.SelectNodes(String.Format("/html/body/table[2]/tr[2]/td[2]/font/div[2]/table/tr/td[{0}]/select/option", td)))
{
attacco = node.NextSibling.InnerText;
if(attacco != "AttackDex: A - G\n" && attacco != "AttackDex: H - R\n" && attacco != "AttackDex: S - Z\n")
{
var url = string.Format("http://www.serebii.net/attackdex-xy/{0}.shtml", attacco.ToLower().Replace(" ", ""));
string attackPage = wc.DownloadString(url);
HtmlDocument doc2 = new HtmlDocument();
doc2.LoadHtml(attackPage);
var category = doc.DocumentNode.SelectSingleNode("/html/body/table[2]/tr[2]/td[2]");
}
}
}
}
And this is the code of html page:
<select name="SelectURL" onchange="document.location.href=document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value" style="color:#383838; font-size: 8pt; background:#CEBC77" size="1">
<option>AttackDex: A - G
</option><option value="/attackdex-xy/absorb.shtml">Absorb</option>
<option value="/attackdex-xy/acid.shtml">Acid</option>
<option value="/attackdex-xy/acidarmor.shtml">Acid Armor</option>
<option value="/attackdex-xy/acidspray.shtml">Acid Spray</option>
<option value="/attackdex-xy/acrobatics.shtml">Acrobatics</option>
<option value="/attackdex-xy/acupressure.shtml">Acupressure</option>
<option value="/attackdex-xy/aerialace.shtml">Aerial Ace</option>
<option value="/attackdex-xy/aeroblast.shtml">Aeroblast</option>
[...]
When I run the program the value of node (in foreach block) is NULL.