Note that there are some explanatory texts on larger screens.

plurals
  1. POExtracting table cell text contents with xpath in rows for consumption?
    text
    copied!<p>I have something along the following lines in terms of HTML. I would like to extract the various contents of the table cells, however I discovered that there are some embedded divs occasionally in the cells and perhaps other oddities that I'm not sure of yet:</p> <pre><code>&lt;p align="center"&gt; &lt;img src="some_image.gif" alt="Some Title"&gt; &lt;/p&gt; &lt;TABLE WIDTH=500 BORDER=1 class=textwhite ALIGN=center CELLPADDING=0 CELLSPACING=0&gt; &lt;TR&gt; &lt;TD colspan=4 ALIGN=center&gt;&lt;b&gt;Title&lt;/b&gt;&lt;/TD&gt; &lt;/TR&gt; &lt;TR&gt; &lt;TD ALIGN=center&gt;Title&lt;/TD&gt; &lt;TD ALIGN=center&gt;date&lt;/TD&gt; &lt;TD ALIGN=center&gt;value&lt;/TD&gt; &lt;TD ALIGN=center&gt;value&lt;/TD&gt; &lt;/TR&gt;&lt;TR&gt; &lt;TD ALIGN=center&gt;Title2&lt;/TD&gt; &lt;TD ALIGN=center&gt;&lt;/TD&gt; &lt;TD ALIGN=center&gt;&lt;div class=redtext&gt;----&lt;/div&gt;&lt;/TD&gt; &lt;TD&gt;&amp;nbsp;&lt;/TD&gt; &lt;/TR&gt;&lt;TR&gt; &lt;TD ALIGN=center&gt;Title3&lt;/TD&gt; &lt;TD ALIGN=center&gt;&lt;div class=yellowtext&gt;value&lt;/div&gt;&lt;/TD&gt; &lt;TD ALIGN=center&gt;&lt;div class=redtext&gt;value&lt;/div&gt;&lt;/TD&gt; &lt;TD ALIGN=center&gt;value&lt;SUP&gt;6&lt;/SUP&gt;&lt;/TD&gt; &lt;/TR&gt;&lt;TR&gt; &lt;TD ALIGN=center&gt;Title4&lt;/TD&gt; &lt;TD ALIGN=center&gt;&lt;div class=bluetext&gt;value&lt;/div&gt;&lt;/TD&gt; &lt;TD ALIGN=center&gt;&lt;div class=redtext&gt;value&lt;/div&gt;&lt;/TD&gt; &lt;TD&gt;&amp;nbsp;&lt;/TD&gt; &lt;/TR&gt;&lt;/TABLE&gt; &lt;blockquote&gt; &lt;p class="textstyle"&gt; Text. &lt;/p&gt; &lt;/blockquote&gt; </code></pre> <p>My first impulse was to extract ALL element texts and just programmatically slice it up. I would watch for Title1, Title2, etc. to know when a row starts and then if a "----" is found meaning no value, just skip this row and move on. However, I realized that there is probably a better way of handling this with xpath directly. </p> <p>How could this be solved with xpath so as to essentially give each cell's final child text content vs having to walk into each div if it exists? Or is there a more xpath like way to approach this?</p> <p>Obviously I'm attempting to have the most flexible solution that will not be brittle if other unexpected elements crop up, even though they are unlikely.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload