Given table:

table='''<table> <tr> <td>Num of something 1</td> <td>4532</td> <td>78</td> </tr> <tr> <td>Num of something 2</td> <td>0</td> <td>235</td> </tr> <tr> <td>Num of something 3</td> <td>8</td> <td>6589</td> </tr> </table>''' if root.xpath('.//td[text()="'+string_parameter+'"]'): result = item.xpath('//td[position()=3]') 

You need to do this: if Num of something 3 is found, then output 6589

    1 answer 1

     from lxml import etree root = etree.fromstring(table) print root.xpath("//td[text()='{}']/../td[3]".format("Num of something 3"))[0].text #выведет 6589 

    Python will first find the element with the text Num of something 3 , then it will rise to a higher level and from there it will find the third element with the tag td