Read html file and get the value of a selected select

Asked

Viewed 359 times

0

I am reading an html file and need to get the value of value of select user selected, how to do ?

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
var select = doc.DocumentNode.SelectNodes("//table//tr//td//select[@class='CC_CxComboBox']");
foreach (var item in select)
{
    var _value = item... //"como pegar o valor do atributo value do select"
}

This is the HTML

 <table>    
        <tr>        
            <td Class='Tit08'>CNPJ:&nbsp; 09876543210000  -  JOÃO DA SILVA      </td>
            <td Class='Tit08'>Grupo:&nbsp;                  
                <select id='grupo' class='CC_CxComboBox'>
                    <option value=''>Selecione</option>
                    <option value=02161 selected>SÃO PAULO</option>         
                </select>
            </td>
        </tr>
    </table>
  • This is exactly what html looks like?

1 answer

1


HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(str);
var select = doc.DocumentNode.SelectNodes("//table//tr//td//select[@class='CC_CxComboBox']//option[@selected]");
foreach (var item in select)
{
    var _value = item.Attributes["value"].Value;
    var _description = item.InnerHtml;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.