How to get table data from tables using xpath

0 votes
asked Sep 2, 2010 by dean

What XPATH query could i use to get the values from the 1st and 3rd <td> tag for each row in a html table.

The XPATH query I have used use is


This only returns the values in the first <td> tag for each row in a table.


I would expect to get the values bob,19,jane,11,cameron and 32 from the below table. But am only getting bob,jane,cameron.


2 Answers

0 votes
answered Sep 2, 2010 by jake-n



I remember doing this in the past and found it rather annoying because it is ugly and long-winded

0 votes
answered Sep 2, 2010 by dimitre-novatchev

@jakenoble's answer:


is correct.

An equivalent XPath expression that avoids the | (union) operator and may be more efficient is:

/table/tr/td[position() = 1 or position() = 3]
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter