c# - How to get value from a <SELECT> <OPTION> -
i'm trying element <select>
, <option>
element.
this 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: - 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 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: - 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 run program value of node (in foreach block) null.
i got work selecting options in document, filtering ones have ancestor select tag name 'selecturl'.
doc.documentnode.selectnodes("//option[ancestor::select[@name='selecturl']]")
Comments
Post a Comment