title: Regex matching items following a header in HTML
body: <p>What should be a fairly simple regex extraction is confounding me.  Couldn't find a similar question on SO, so happy to be pointed to one if it exists.  Given the following HTML:</p>
  
  <p><code>&lt;h1 class="title"&gt;Title One&lt;/h1&gt;&lt;p&gt;&lt;a href="#"&gt;40.5&lt;/a&gt;&lt;a href="#"&gt;31.3&lt;/a&gt;&lt;/p&gt;</code></p>
  
  <p><code>&lt;h1 class="title alternate"&gt;Title Two&lt;/h1&gt;&lt;p&gt;&lt;a href="#"&gt;12.1&lt;/a&gt;&lt;a href="#"&gt;82.0&lt;/a&gt;&lt;/p&gt;</code></p>
  
  <p>(amongst a larger document - the extracts will most probably run across multiple lines)</p>
  
  <p>How can I construct a regular expression that finds the text within the A tags, within the first P following an H1?  The regex will go in a loop, such that I can pass in the header, in order to retrieve the items that follow.</p>
  
  <p><code>&lt;a[^&gt;]*&gt;([0-9.]+?)&lt;/a&gt;</code> obviously matches all items in a tag (and should be fine as a tags cannot be nexted), but I can't tie them to an H1.</p>
  
  <p><code>.+Title One.+&lt;a[^&gt;]*&gt;([0-9.]+?)&lt;/a&gt;&lt;/p&gt;</code> fails.</p>
  
  <p>I had tried to use look behind as so:</p>
  
  <p><code>(?&lt;=Title One.+)&lt;a[^&gt;]*&gt;([0-9.]+?)&lt;/a&gt;&lt;/p&gt;</code> and some variations but it is only allowed for fixed width matches (which won't be the case here).</p>
  
  <p>For context, this will be using Python's regex engine.  I know regex isn't necessarily the best solution for this, so alternative suggestions using DOM or something else also gratefully received :)</p>
  
  <p><hr>
  <strong>Update</strong></p>
  
  <p>To clarify from the above, I'd like to get back the following:</p>
  
  <p><code>{"Title One": ["40.5", "31.3"], "Title Two": ["12.1", "82.0"]}</code></p>
  
  <p>(not that I need help composing the dictionary, but it does demonstrate how I need the values to be related to the title).</p>
  
  <p>So far BeautifulSoup looks like the best shot.  LXML will also probably work as the source HTML isn't really tag-soup - it's pretty well-structured, at least in the places I'm interested in.</p>
  
  <hr>