Python: Using xpath locally / on a specific element
问题 I'm trying to get the links from a page with xpath. The problem is that I only want the links inside a table, but if I apply the xpath expression on the whole page I'll capture links which I don't want. For example: tree = lxml.html.parse(some_response) links = tree.xpath("//a[contains(@href, 'http://www.example.com/filter/')]") The problem is that applies the expression to the whole document. I located the element I want, for example: tree = lxml.html.parse(some_response) root = tree.getroot