With the html agility pack, can I access the innertext of 2nd TR's 2nd TD?

c# html html-agility-pack

Question

With the html agility pack, how can I get the innertext of the second TR's second TD, i.e. John Paul and 30?

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableClass">
    <form name="form1" action="goto.php" method="post">
        <tr>

            <td height="35" colspan="2" class="tdClass"
                style="padding-top:5px "><img
                src="./include/gif/grey-sub-header-ex-customer.gif"
                alt="details" width="162" height="20" /></td>
            <td valign="top" class="tdClass">&nbsp;</td>
        </tr>

        <tr class="trRow">
            <td width="190" class="tdDataRow">name:</td>
            <td class="tdDataName">john paul</td>
            <td class="whiteClass">&nbsp;</td>
        </tr>

        <tr class="trRow">
            <td width="190" class="tdDataRow">age:</td>
            <td class="tdDataName">30</td>
            <td class="whiteClass">&nbsp;</td>
        </tr>
1
3
5/9/2011 7:41:00 PM

Popular Answer

after you've got theHtmlDocument loaded (by eithernew HtmlWeb().Load("http://www.site.com") or bydoc.Load(...) ), you can:

//Get 2nds <td> tags inside all tr class of that table
var tds = doc.DocumentNode.SelectNodes("//table[@class='tableClass']/tr[@class='trRow']/td[2]");
foreach (var td in tds) {
    Console.WriteLine(td.InnerText);
}

Edit:
I changed the code since<tr> No tags were present.<form> .

5
5/9/2011 7:39:46 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow