title: BeautifulSoup: find all tags before stopping condition is met
body: <p>I'm trying to extract a class tag from an HTML file, but only if it is located before a given stopping point. What I have is:</p>
  
  <pre><code>import requests
  from bs4 import BeautifulSoup
  
  page = requests.get("https://mysite")
  soup = BeautifulSoup(page.content, 'html.parser')
  class_extr = soup.find_all("span", class_="myclass")
  </code></pre>
  
  <p>This works, but it finds <em>all</em> instances of <code>myclass</code>, and i only want those <em>before</em> the following text shows in the <code>soup</code>:</p>
  
  <pre><code>&lt;h4 class="cat-title" id="55"&gt;
   Title text N1
   &lt;small&gt;
    Title text N2.
   &lt;/small&gt;
  &lt;/h4&gt;
  </code></pre>
  
  <p>The thing that makes this block unique are the <code>Title text N</code> lines, especially the <code>Title text N2.</code> line. There are many <code>cat-title</code> tags before, so I can't use that as a stopping condition.</p>
  
  <p>The code surrounding this block looks like this:</p>
  
  <pre><code>...
  &lt;div class="myc"&gt;
  &lt;a class="bbb" href="linkhere_893"&gt;
  &lt;span class="myclass"&gt;Text893&lt;/span&gt;
  &lt;img data-lazy="https://link893.jpg"/&gt;
  &lt;/a&gt;
  &lt;/div&gt;
  &lt;div class="myc"&gt;
  &lt;a class="bbb" href="linkhere_96"&gt;
  &lt;span class="myclass"&gt;Text96&lt;/span&gt;
  &lt;img data-lazy="https://link96.jpg"/&gt;
  &lt;/a&gt;
  &lt;/div&gt;
  &lt;/div&gt;&lt;!-- This closes a list that starts above --&gt;
  &lt;h4 class="cat-title" id="55"&gt;Title text N1 &lt;small&gt; Title text N2.&lt;/small&gt;&lt;/h4&gt;
  &lt;div class="list" id="55"&gt;
  &lt;div class="myc"&gt;
  &lt;a class="bbb" href="linkhere_34"&gt;
  &lt;span class="myclass"&gt;Text34&lt;/span&gt;
  &lt;img data-lazy="https://link34.jpg"/&gt;
  &lt;/a&gt;
  &lt;/div&gt;
  &lt;div class="myc"&gt;
  ...
  </code></pre>
  
  <p>continuing both above and below.</p>
  
  <p>How can I do this?</p>