How to select all tr ​​except the last two tr

In lxml, I use xpath to select the whole tr in the table (which has a different number of rows), with the exception of the last two rows that contain gibberish.

Is there a pattern match that excludes the last two lines? I was looking through xpath tutorials and apparently there is an “except” statement as well as “last ()”, but it doesn't seem to work for my code to work.

While I have it. What can I add to this pattern to exclude the last two lines? The main problem is that the number tr is changing.

result = doc.xpath("//tr")

I think I could turn this into a list and just delete the last two elements, but is there an easier / more elegant solution?

Thanks in advance!

+3
source share
2
result = doc.xpath("//tr")[0:-2]

.

+2

expressionSelectingTheTable/tr[not(position() > last() -2)]

expressionSelectingTheTable XPath, , (, //table[@id='foo'])

XPath tr table, .

+9

Source: https://habr.com/ru/post/1791394/


All Articles