vb.net - How to read 'n' following tags after each selected node -


i'm trying each player stats following html table using vb .net , html agility pack (hap), don't know how select tags after each player row.

    <table class="stats" cellspacing="0">    <tr class="statsgreen">       <td colspan="10" class="estverdel">team a</td>       <td colspan="2">reb</td>       <td colspan="4">&nbsp;</td>       <td colspan="2">blk</td>       <td>&nbsp;</td>       <td colspan="2">pf</td>       <td>&nbsp;</td>       <td>&nbsp;</td>    </tr>    <tr class="statsgreen">       <td>num</td>       <td>name</td>       <td>min</td>       <td>gs</td>       <td>t2</td>       <td>t2 %</td>       <td>t3</td>       <td>t3 %</td>       <td>t1</td>       <td>t1 %</td>       <td>t</td>       <td>d+o</td>       <td>a</td>       <td>st</td>       <td>lo</td>       <td>c</td>       <td>r</td>       <td>c</td>       <td>m</td>       <td>r</td>       <td>c</td>       <td>+/-</td>       <td>pie</td>    </tr>        <tr>       <td>6</td>       <td><a href="/player.php?id=001">player 1</a></td>       <td>30:22</td>       <td>18</td>       <td>4/10</td>       <td>40%</td>       <td>2/6</td>       <td>33%</td>       <td>4/4</td>       <td>100%</td>       <td>9</td>       <td>5+4</td>       <td>1</td>       <td>1</td>       <td>0</td>       <td>0</td>       <td>0</td>       <td>0</td>       <td>0</td>       <td>3</td>       <td>4</td>       <td>10</td>       <td>20</td>    </tr>    <tr>       <td>6</td>       <td><a href="/player.php?id=002">player 2</a></td>       <td>30:22</td>       <td>18</td>       <td>4/10</td>       <td>40%</td>       <td>2/6</td>       <td>33%</td>       <td>4/4</td>       <td>100%</td>       <td>9</td>       <td>5+4</td>       <td>1</td>       <td>1</td>       <td>0</td>       <td>0</td>       <td>0</td>       <td>0</td>       <td>0</td>       <td>3</td>       <td>4</td>       <td>10</td>       <td>20</td>    </tr>    ...    ...    <tr class="statsgreen">       <td colspan="10" class="estverdel">team b</td>       <td colspan="2">reb</td>       <td colspan="4">&nbsp;</td>       <td colspan="2">blk</td>       <td>&nbsp;</td>       <td colspan="2">pf</td>       <td>&nbsp;</td>       <td>&nbsp;</td>    </tr>    <tr class="statsgreen">       <td>num</td>       <td>name</td>       <td>min</td>       <td>gs</td>       <td>t2</td>       <td>t2 %</td>       <td>t3</td>       <td>t3 %</td>       <td>t1</td>       <td>t1 %</td>       <td>t</td>       <td>d+o</td>       <td>a</td>       <td>st</td>       <td>lo</td>       <td>c</td>       <td>r</td>       <td>c</td>       <td>m</td>       <td>r</td>       <td>c</td>       <td>+/-</td>       <td>pie</td>    </tr>        <tr>       <td>6</td>       <td><a href="/player.php?id=013">player 13</a></td>       <td>30:22</td>       <td>18</td>       <td>4/10</td>       <td>40%</td>       <td>2/6</td>       <td>33%</td>       <td>4/4</td>       <td>100%</td>       <td>9</td>       <td>5+4</td>       <td>1</td>       <td>1</td>       <td>0</td>       <td>0</td>       <td>0</td>       <td>0</td>       <td>0</td>       <td>3</td>       <td>4</td>       <td>10</td>       <td>20</td>    </tr> </table> 

this uncomplete code in vb.net getting teams , player names:

private sub btngetstats_click(sender object, e eventargs) handles btngetstats.click     dim doc new htmldocument                         doc.load("c:\001.html")      'get team names       each nodeteams htmlnode in doc.documentnode.selectnodes("//td[@class=""estverdel""]")                             messagebox.show("team: " + nodeteams.innertext)                     next      'get player names     each nodeplayers htmlnode in doc.documentnode.selectnodes("//a[contains(@href, '/player')]")         messagebox.show(nodeplayers.innertext)         next end sub 

is there xpath sentence use selecting each player node , go through each 1 of following 21 stats fields?.

as alternative suppose nodeplayers.line , read following 21 lines using system.io.streamreader maybe hap can in smart way.

one possibility use parentnode property of htmlnode player object:

  • take parent of parent of found player node (the tr node <tr><td><a player>...)
  • take child nodes (all td nodes)
  • skip first 2 of child nodes using linq skip (the number , player link)
  • take rest of child nodes

modifying second loop this:

   'get player names    each nodeplayers htmlnode in doc.documentnode.selectnodes("//a[contains(@href, '/player')]")         console.writeline("player: " + nodeplayers.innertext)         ' select parent node (tr) of player (a) parent node (td), skip first 2 , take rest          each node htmlnode in nodeplayers.parentnode.parentnode.childnodes.skip(2).tolist()             console.writeline(node.innertext)         next    next 

returns values each player:

team: team team: team b player: player 1    30:22   18 4/10  40%  2/6 33%  4/4 100%  9  5+4   1   1  0     0    0   0     0     3     4     10     20 ... 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -