title: Extracting data from HTML table
body: <p>I am looking for a way to get certain info from HTML in linux shell environment. </p>
  
  <p>This is bit that I'm interested in :</p>
  
  <pre><code>&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;
  </code></pre>
  
  <p>And I want to store in shell variables or echo these in key value pairs extracted from above html. Example :</p>
  
  <pre><code>Tests         : 103
  Failures      : 24
  Success Rate  : 76.70 %
  and so on..
  </code></pre>
  
  <p>What I can do at the moment is to create a java program that will use sax parser or html parser such as jsoup to extract this info. </p>
  
  <p>But using java here seems to be overhead with including the runnable jar inside the "wrapper" script you want to execute.</p>
  
  <p>I'm sure that there must be "shell" languages out there that can do the same i.e. perl, python, bash etc. </p>
  
  <p>My problem is that I have zero experience with these, can somebody help me resolve this "fairly easy" issue</p>
  
  <p><strong>Quick update:</strong></p>
  
  <p>I forgot to mention that I've got more tables and more rows in the .html document sorry about that (early morning).</p>
  
  <p><strong>Update #2:</strong></p>
  
  <p>Tried to install Bsoup like this since I don't have root access :</p>
  
  <pre><code>$ wget http://www.crummy.com/software/BeautifulSoup/bs4/download/4.0/beautifulsoup4-4.1.0.tar.gz
  $ tar -zxvf beautifulsoup4-4.1.0.tar.gz
  $ cp -r beautifulsoup4-4.1.0/bs4 .
  $ vi htmlParse.py # (paste code from ) Tichodromas' answer, just in case this (http://pastebin.com/4Je11Y9q) is what I pasted
  $ run file (python htmlParse.py)
  </code></pre>
  
  <p><em>error:</em></p>
  
  <pre><code>$ python htmlParse.py
  Traceback (most recent call last):
    File "htmlParse.py", line 1, in ?
      from bs4 import BeautifulSoup
    File "/home/gdd/setup/py/bs4/__init__.py", line 29
      from .builder import builder_registry
           ^
  SyntaxError: invalid syntax
  </code></pre>
  
  <p><strong>Update #3 :</strong></p>
  
  <p>Running Tichodromas' answer get this error :</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 27, in ?
      headings = [th.get_text() for th in table.find("tr").find_all("th")]
  TypeError: 'NoneType' object is not callable
  </code></pre>
  
  <p>any ideas?</p>