How to get the value from a specific cell C# Html-Agility-Pack -


how value specific location in second table in document. need value second cell down , third column on in html document below. how do this.

<html> <head> <title>tables</title> </head> <body> <table border="1">   <tr>     <th>room</th>     <th>location</th>   </tr>   <tr>     <td>paint</td>     <td>a4</td>   </tr>   <tr>     <td>stock</td>     <td>b3</td>   </tr>   <tr>     <td>assy</td>     <td>n9</td>   </tr> </table> <p></p> <table border="1">   <tr>     <th>product</th>     <th>mat'l</th>     <th>weight</th>     <th>size</th>   </tr>   <tr>     <td>cover</td>     <td>plastic</td>     <td>4</td>     <td>16</td>   </tr>   <tr>     <td>retainer</td>     <td>steel</td>     <td>12</td>     <td>8</td>   </tr>   <tr>     <td>pin</td>     <td>bronze</td>     <td>18</td>     <td>7</td>   </tr> </table> <p></p> <table border="1">   <tr>     <th>process</th>     <th>location</th>     <th>number</th>   </tr>   <tr>     <td>trim</td>     <td>s2</td>     <td>8</td>   </tr>   <tr>     <td>finish</td>     <td>d2</td>     <td>3</td>   </tr> </table> </body> </html> 

thanks!

also... please newbie out!!! please direct me resource can me understand syntax of html-agility-pack (hap). have chm file hap - i've tried use , i've tried use vs's object browser hap, it's cryptic me @ point.

html agility pack equipped xpath evaluator follows .net xpath syntax on parsed html nodes. note xpath expression used library require elements , attribute names lowercase, independently original html source.

so in case, can cell 3rd column, 2nd row, 2nd table expression this:

htmldocument doc = new htmldocument(); doc.load(youtesthtmlfilepath);  htmlnode node = doc.documentnode.selectsinglenode("//table[2]/tr[2]/td[3]"); console.writeline(node.innertext); // output "4" 

//table means table element recursively root. [2] means take 2nd table.

/tr means tr element current table. [2] means take 2nd row.

/td means td element current row. [3] means take 3nd cell.

you can find xpath tutorials here: xpath tutorial


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -