title: Python/lxml/Xpath: How do I find the row containing certain text?
body: <p>Given the URL <a href="http://www.smartmoney.com/quote/FAST/?story=financials&amp;timewindow=1&amp;opt=YB&amp;isFinprint=1&amp;framework.view=smi_emptyView" rel="nofollow">http://www.smartmoney.com/quote/FAST/?story=financials&amp;timewindow=1&amp;opt=YB&amp;isFinprint=1&amp;framework.view=smi_emptyView</a> , how would you capture and print the contents of an entire row of data?  </p>
  
  <p>For example, what would it take to get an output that looked something like:
  "Cash &amp; Short Term Investments 144,841 169,760 189,252 86,743 57,379"?  Or something like "Property, Plant &amp; Equipment - Gross 725,104 632,332 571,467 538,805 465,493"?</p>
  
  <p>I've been introduced to the basics of Xpath through sites <a href="http://www.techchorus.net/web-scraping-lxml" rel="nofollow">http://www.techchorus.net/web-scraping-lxml</a> .  However, the Xpath syntax is still largely a mystery to me.</p>
  
  <p>I already have successfully done this in BeautifulSoup.  I like the fact that BeautifulSoup doesn't require me to know the structure of the file - it just looks for the element containing the text I search for.  Unfortunately, BeautifulSoup is too slow for a script that has to do this THOUSANDS of times.  The source code for my task in BeautifulSoup is (with title_input equal to "Cash &amp; Short Term Investments"):</p>
  
  <pre><code>    page = urllib2.urlopen (url_local)
      soup = BeautifulSoup (page)
      soup_line_item = soup.findAll(text=title_input)[0].parent.parent.parent
      list_output = soup_line_item.findAll('td') # List of elements
  </code></pre>
  
  <p>So what would the equivalent code in lxml be?</p>
  
  <p>EDIT 1: The URLs were concealed the first time I posted.  I have now fixed that.</p>
  
  <p>EDIT 2: I have added my BeautifulSoup-based solution to clarify what I'm trying to do.</p>
  
  <p>EDIT 3: +10 to root for your solution.  For the benefit of future developers with the same question, I'm posting here a quick-and-dirty script that worked for me:</p>
  
  <pre><code>    #!/usr/bin/env python
      import urllib
      import lxml.html
  
      url = 'balancesheet.html'
  
      result = urllib.urlopen(url)
      html = result.read()
  
  
      doc = lxml.html.document_fromstring(html)
      x = doc.xpath(u'.//th[div[text()="Cash &amp; Short Term Investments"]]/following-sibling::td/text()')
      print x
  </code></pre>