i'm new html agility pack , xpath. have table part of is:
... <tbody class="tdata"> <tr bgcolor="#ffffff"> <td nowrap>crr004</td> <td nowrap>carrie</td> <td nowrap>021</td> <td nowrap>coal</td> <td nowrap>0.800</td> <td nowrap>55.000</td> <td nowrap>55.800</td> <td nowrap>fcr a</td> <td nowrap> </td> <td nowrap> </td> <td nowrap> </td> </tr></tbody> ... <tbody class="tdata"> <tr bgcolor="#ffffff"> <td nowrap>crr004</td> <td nowrap>carrie</td> <td nowrap>021</td> <td nowrap>coal</td> <td nowrap>0.800</td> <td nowrap>99.500</td> <td nowrap>100.300</td> <td nowrap>fcl b</td> <td nowrap> </td> <td nowrap> </td> <td nowrap> </td> </tr></tbody> <tbody class="tdata"> <tr bgcolor="#ffffff"> <td nowrap>crr004</td> <td nowrap>carrie</td> <td nowrap>034</td> <td nowrap>bone</td> <td nowrap>0.100</td> <td nowrap>100.300</td> <td nowrap>100.400</td> <td nowrap>fcl b</td> <td nowrap> </td> <td nowrap> </td> <td nowrap> </td> </tr></tbody> <tbody class="tdata"> <tr bgcolor="#ffffff"> <td nowrap>crr004</td> <td nowrap>carrie</td> <td nowrap>021</td> <td nowrap>coal</td> <td nowrap>0.400</td> <td nowrap>100.400</td> <td nowrap>100.800</td> <td nowrap>fcl b</td> <td nowrap> </td> <td nowrap> </td> <td nowrap> </td> </tr></tbody> using html agility pack, can grab entire table with:
doc.documentnode.selectnodes("//tbody[@class='tdata']/tr") but want select row 8th column contains "fcr a" last row containing "fcl b". row 2 row 14.
crr004 carrie 540 ss 1.100 53.900 55.000 crr004 carrie 021 coal 0.800 55.000 55.800 fcr crr004 carrie 124 sh 4.200 55.800 60.000 crr004 carrie 320 s sh 1.400 60.000 61.400 crr004 carrie 540 ss 2.400 61.400 63.800 crr004 carrie 320 s sh 0.300 63.800 64.100 crr004 carrie 540 ss 15.900 64.100 80.000 crr004 carrie 749 ss w/coal str 10.000 80.000 90.000 crr004 carrie 540 ss 7.200 90.000 97.200 crr004 carrie 124 sh 0.500 97.200 97.700 crr004 carrie 114 black sh 1.800 97.700 99.500 crr004 carrie 021 coal 0.800 99.500 100.300 fcl b crr004 carrie 034 bone 0.100 100.300 100.400 fcl b crr004 carrie 021 coal 0.400 100.400 100.800 fcl b crr004 carrie 120 cl sh 0.800 100.800 101.600 i tried doc.documentnode.selectnodes("//tbody[@class='tdata']/tr[following-sibling::td[8]='fcr a' , preceding-sibling::td[8]='fcl b']")) among others no avail. appreciated. thanks.
after playing around splash's suggestion, works:
//tr[contains(.,'fcr a')]|//tr[following::tr[td[8][.= 'fcl b']][last()] , preceding::tr[td[8][.= 'fcr a']][last()]]|//tr[contains(.,'fcl b')] but shorter expression appreciated.
Comments
Post a Comment