title: Python/xpath get instances of text in arbitrary element
body: <p>Given the following:</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;div&gt;Text 1&lt;/div&gt;
          &lt;/td&gt;
          &lt;td&gt;
              Text 2
          &lt;/td&gt;
          &lt;td&gt;
              &lt;div&gt;
                  &lt;a href="#"&gt;Text 3&lt;/a&gt;
              &lt;/div&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          ...
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Given the above table, how would I extract all the text? Note that the number of nested elements is arbitrary so I can't just look for the first sibling, zero-th sibling, and second sibling.</p>
  
  <p>I'm looking for a general way to extract the text.</p>
  
  <pre><code>In [1]: d="""&lt;table&gt;
     ...:     &lt;tr&gt;
     ...:         &lt;td&gt;
     ...:             &lt;div&gt;Text 1&lt;/div&gt;
     ...:         &lt;/td&gt;
     ...:         &lt;td&gt;
     ...:             Text 2
     ...:         &lt;/td&gt;
     ...:         &lt;td&gt;
     ...:             &lt;div&gt;
     ...:                 &lt;a href="#"&gt;Text 3&lt;/a&gt;
     ...:             &lt;/div&gt;
     ...:         &lt;/td&gt;
     ...:     &lt;/tr&gt;
     ...:     &lt;tr&gt;
     ...:         ...
     ...:     &lt;/tr&gt;
     ...: &lt;/table&gt;"""
  
  In [3]: from lxml import etree
  
  In [4]: f = etree.HTML(d)
  
  In [5]: f.xpath('normalize-space(string(/table))')
  Out[5]: ''
  
  In [6]: f.xpath('normalize-space(string(//table))')
  Out[6]: 'Text 1 Text 2 Text 3 ...
  </code></pre>