Taking only 1 on 3

时间:2016-04-25 09:22:14

标签: python xpath

I'm actually parsing website to extract data in Python using Xpaths.

But I don't know how to this thing :

<tr> </tr>
<tr> </tr>
<tr> Data </tr>
<tr> </tr>
<tr> </tr>
<tr> Data </tr>
<tr> </tr>
<tr> </tr>
<tr> Data </tr>

I know I can do //tr[3] to get the thrid one. But how can I do to get all thirds ?

2 个答案:

答案 0 :(得分:3)

Use position funxtion and take the remainder of the division by 3. Because xpath understand zero as false, you can write

//tr[not(position() mod 3)]

答案 1 :(得分:3)

You can use position() function:

//tr[position() mod 3 = 0]