c# - Html Agility Pack - loop through rows and columns -


i getting involved on parsing html files using c# language , htmlagilitypack.

i trying each row 2 columns values insert them database. running following:

foreach (htmlnode row in htmldoc.documentnode.selectnodes("//tr"))     {     foreach (htmlnode cell in row.selectnodes("//td"))     {     console.writeline(cell.innertext);     }     } 

i got error loop on td , not ones includes in current tr.

my html looks this:

<table>         <tr>                         <th align="center" width="50"><b>column 1</b></th>                       <th align="center" width="210"><b>column 2</b></th>                           </tr>                   <tr bgcolor="#ffffff">                 <td align="left"> </td>                              <td align="left"></td>                                        </tr>                  <tr bgcolor="#dddddd">                 <td align="left"> </td>                              <td align="left"></td>                                        </tr>                  <tr bgcolor="#ffffff">                 <td align="left"> </td>                              <td align="left"></td>                                        </tr> 

just let know have updated code works not looks @ all:

j = htmldoc.documentnode.selectnodes("//tr").count;                     if (j != 0)                     {                          (int = 2; < j; ++i)                         {                             (int k = 1; k < 3; k++)                             {                                 htmlnodecollection row = htmldoc.documentnode.selectnodes("/html/body/table/tr[" + + "]/td[" + k + "]");                                 console.writeline("nb or row" + row.count);                                   console.writeline(row[0].innertext);                                 //console.read();                              }                         }                     } 

if have idea enhance code great.

thanks, damien


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -