Access to inner text of 2nd TR of 2nd TD with html flexibility package?

I want to access in C #, the inner text of the 2nd TR of the 2nd TD, i.e. john paul and 30 with the hmml flexibility package?

<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>
+3
source share
2 answers

After downloading HtmlDocument(either new HtmlWeb().Load("http://www.site.com"), or doc.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 edited the code because the tags <tr>were not inside <form>.

+5
source

add attribute runat="server"to td you want to access

        <td id="tdname" runat="server" class="tdDataName">john paul</td>

then u can directly access the inner text as

 string name=tdname.InnerText;      //where tdname is the id of td
0
source

All Articles