开发者

xpath expression to find url and data

i want to get the values of every table and the href value for every within the table given below. Being new to xpath, i am finding it difficult to write xpath expression. However understanding what an xpath expression does lies somewhat in an easier category.

the expected output

http://a.com/   data for a  526735  Z
http://b.com/   data for b  522273  Z
http://c.com/   data for c  513335  Z  

<table class = dataTabe>
<tbody>
<tr>
<td><a HREF="http://a.com/" target="_parent">data for a</a></td>
<td class="numericalColumn">526735</td>
<td class="numericalColumn">Z</td></tr>
<tr>
<td><a HREF="http://b.com/" target="_parent">data for b</a></td>
<td class="numericalColumn">522273</td>
<td class="numericalColumn">B</td></tr>
<tr>
<td><a HREF="http://c.com" target="_parent">data for c</a></td>
<td class="numericalColumn">513335</td>
<td class="numericalColumn"&g开发者_JS百科t;B</td></tr>
</tbody>
</table>


You'll need two things: an XPath query which locates the wanted nodes and a second which outputs the text as you want it. Since you don't give more information about the languages you're using I'm putting together some pseudocode:

foreach node in document.select("//table[class='dataTable']//tr[td/a/@HREF]")
  write node.select("concat(td/a/@HREF,'   ',.)")


This site has a great free tool for building XPath Expressions (XPath Builder):

http://www.bubasoft.net/


Use this XPath: //tr/td/a/@HREF | //tr//text()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜