title: Parsing HTML File BeautifulSoup
body: <p>I'm trying to parse a local <code>html</code> file with BeautifulSoup but having trouble navigating the tree.</p>
  
  <p>The file is in the following format:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="contents"&gt;
    &lt;h1&gt;
      USERNAME
    &lt;/h1&gt;
  &lt;div&gt;
    &lt;div class="thread"&gt;
       N1, N2
       &lt;div class="message"&gt;
         &lt;div class="message_header"&gt;
           &lt;span class="user"&gt;
             USERNAME
           &lt;/span&gt;
         &lt;span class="meta"&gt;
           Thursday, 1 January 2015 at 19:52 UTC
         &lt;/span&gt;
       &lt;/div&gt;
     &lt;/div&gt;
     &lt;p&gt;
        They're just friends
     &lt;/p&gt;
     &lt;div class="message"&gt;
         &lt;div class="message_header"&gt;
           &lt;span class="user"&gt;
             USERNAME
           &lt;/span&gt;
         &lt;span class="meta"&gt;
           Thursday, 1 January 2015 at 19:52 UTC
         &lt;/span&gt;
       &lt;/div&gt;
     &lt;/div&gt;
     &lt;p&gt;
        MESSAGE
     &lt;/p&gt;
   ...
  </code></pre>
  
  <p>I want to extract, for each thread:</p>
  
  <p>for each <code>div</code> <code>class='message'</code>:</p>
  
  <ul>
  <li>the <code>span</code> <code>class='user'</code> and meta data</li>
  <li>the message in the <code>p</code> directly after</li>
  </ul>
  
  <p>This is a long file with many of these threads and many messages within each thread.</p>
  
  <p>So far I've just opened the file and turned it into a soup</p>
  
  <pre><code>raw_data = open('file.html', 'r')
  soup = BeautifulSoup(raw_data)
  
  contents = soup.find('div', {'class' : 'contents'})
  </code></pre>
  
  <p>I'm looking at storing this data in a dictionary in the format</p>
  
  <pre><code>dict[USERNAME] = ([(MESSAGE1, time1), [MESSAGE2, time2])
  </code></pre>