title: XPath for sub-element's text value in lxml
body: <p>First of all, is it possible to do such thing?</p>
  
  <p>I have been trying out to generate Xpath expression by using "sub-element text values" present in webpage. Trying to do this using lxml (etree, html, getpath), ElementTree modules in Python. But I don't know how to generate Xpath expression for a value present in the webpage. I totally know about Scrapy framework in python, but this is different. </p>
  
  <p>Below is the my incomplete code..</p>
  
  <pre><code>import urllib2, re
  from lxml import etree
  
  def wgetUrl(target):
      try:
          req = urllib2.Request(target)
          req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3 Gecko/2008092417 Firefox/3.0.3')
          response = urllib2.urlopen(req)
          outtxt = response.read()
          response.close()
      except:
          return ''
      return outtxt
  
  
  newUrl = 'http://www.iupui.edu/~webtrain/tutorials/tables.html' # homepage
  
  dt = wgetUrl(newUrl)
  parser = etree.HTMLParser()
  tree   = etree.fromstring(dt, parser)
  </code></pre>
  
  <p>As per the <a href="http://lxml.de/xpathxslt.html#the-xpath-method" rel="nofollow">lxml documentation</a> they are creating element tree manually, but how can I use my read and parsed html data (in my example variable <code>tree</code> or <code>data</code>) to access the sub-element. <strong>Or more importantly, if possible the sub-element text value.</strong></p>
  
  <p>Let's say in the above example webpage, I want to search table <strong>"Supplies and Expenses"</strong> and generate Xpath expression dynamically by that <strong>value - Supplies and Expenses</strong></p>
  
  <p>Is there any option to do so !!! Ultimate goal, I would like to achieve is read webpage and generate Xpath for the <strong>sub-element text value</strong> present in webpage.</p>