title: Python: Using xpath locally / on a specific element
body: <p>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.</p>
  
  <p>For example:</p>
  
  <pre><code>tree = lxml.html.parse(some_response)
  links = tree.xpath("//a[contains(@href, 'http://www.example.com/filter/')]")
  </code></pre>
  
  <p>The problem is that applies the expression to the whole document. I located the element I want, for example:</p>
  
  <pre><code>tree = lxml.html.parse(some_response)
  root = tree.getroot()
  table = root[1][5] #for example
  links = table.xpath("//a[contains(@href, 'http://www.example.com/filter/')]")
  </code></pre>
  
  <p>But that seems to be performing the query in the whole document as well, as I still am capturing the links outside of the table. <a href="http://codespeak.net/lxml/xpathxslt.html" rel="noreferrer">This page</a> says that "When xpath() is used on an Element, the XPath expression is evaluated against the element (if relative) or against the root tree (if absolute):". So, what I using is an absolute expression and I need to make it relative? Is that it?</p>
  
  <p>Basically, how can I go about filtering only elements that exist inside of this table?</p>