title: Python/Beautiful Soup find particular heading output full div
body: <p>I'm attempting to parse a very extensive HTML document looks something like:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="reportsubsection n" &gt;&lt;br&gt;
     &lt;h2&gt; part 1 &lt;/h2&gt;&lt;br&gt;
     &lt;p&gt; insert text here &lt;/p&gt;&lt;br&gt;
    &lt;table&gt; crazy table thing here &lt;/table&gt;&lt;br&gt;
  &lt;/div&gt;
  &lt;div class="reportsubsection n"&gt;&lt;br&gt;
     &lt;h2&gt; part 2 &lt;/h2&gt;&lt;br&gt;
     &lt;p&gt; insert text here &lt;/p&gt;&lt;br&gt;
     &lt;table&gt; crazy table thing here &lt;/table&gt;&lt;br&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Need to parse out the second div based on h2 having text "Part 2". Iwas able to break out all divs with:</p>
  
  <pre><code>divTag = soup.find("div", {"id": "reportsubsection"})
  </code></pre>
  
  <p>but didn't know how to dwindle it down from there. Other posts I found I was able to find the specific text "part 2 but I need to be able to output the whole DIV section it is contained in.</p>
  
  <p>EDIT/UPDATE</p>
  
  <p>Ok sorry but I'm still a little lost. Here is what I've got now. I feel like this should be so much simpler than I'm making it. Thanks again for all the help<br></p>
  
  <pre><code>divTag = soup.find("div", {"id": "reportsubsection"})&lt;br&gt;
  for reportsubsection in soup.select('div#reportsubsection #reportsubsection'):&lt;br&gt;
      if not reportsubsection.findAll('h2', text=re.compile('Finding')):&lt;br&gt;
          continue&lt;br&gt;
  print divTag
  </code></pre>