Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A Python solution using <a href="http://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="noreferrer">BeautifulSoup4</a> (<strong>Edit:</strong> with proper skipping. <strong>Edit3:</strong> Using <code>class="details"</code> to select the <code>table</code>):</p> <pre><code>from bs4 import BeautifulSoup html = """ &lt;table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"&gt; &lt;tr valign="top"&gt; &lt;th&gt;Tests&lt;/th&gt; &lt;th&gt;Failures&lt;/th&gt; &lt;th&gt;Success Rate&lt;/th&gt; &lt;th&gt;Average Time&lt;/th&gt; &lt;th&gt;Min Time&lt;/th&gt; &lt;th&gt;Max Time&lt;/th&gt; &lt;/tr&gt; &lt;tr valign="top" class="Failure"&gt; &lt;td&gt;103&lt;/td&gt; &lt;td&gt;24&lt;/td&gt; &lt;td&gt;76.70%&lt;/td&gt; &lt;td&gt;71 ms&lt;/td&gt; &lt;td&gt;0 ms&lt;/td&gt; &lt;td&gt;829 ms&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;""" soup = BeautifulSoup(html) table = soup.find("table", attrs={"class":"details"}) # The first tr contains the field names. headings = [th.get_text() for th in table.find("tr").find_all("th")] datasets = [] for row in table.find_all("tr")[1:]: dataset = zip(headings, (td.get_text() for td in row.find_all("td"))) datasets.append(dataset) print datasets </code></pre> <p>The result looks like this:</p> <pre><code>[[(u'Tests', u'103'), (u'Failures', u'24'), (u'Success Rate', u'76.70%'), (u'Average Time', u'71 ms'), (u'Min Time', u'0 ms'), (u'Max Time', u'829 ms')]] </code></pre> <p><strong>Edit2:</strong> To produce the desired output, use something like this:</p> <pre><code>for dataset in datasets: for field in dataset: print "{0:&lt;16}: {1}".format(field[0], field[1]) </code></pre> <p>Result:</p> <pre><code>Tests : 103 Failures : 24 Success Rate : 76.70% Average Time : 71 ms Min Time : 0 ms Max Time : 829 ms </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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