title: Beautifulsoup Strainer to strain items from a specific container only
body: <p>Is it possible to make a Beautifulsoup Strainer that strains all 'order-cards' from 'container-01' only (without 'order-cards' from other containers)?
  Below the sample HTML</p>
  <pre><code>&lt;div class=&quot;items-container&quot; container-id=&quot;container-01&quot;&gt;
      &lt;div class=&quot;order-card&quot;&gt;order_01
          &lt;div class=&quot;item-card&quot;&gt;item1&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;item2&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;item3&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;item4&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;order-card&quot;&gt;order_02
          &lt;div class=&quot;item-card&quot;&gt;itemA&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;itemB&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;itemC&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;itemD&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;order-card&quot;&gt;order_03
          &lt;div class=&quot;item-card&quot;&gt;itemW&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;itemX&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;itemY&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;itemZ&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;item&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;items-container&quot; container-id=&quot;container-02&quot;&gt;
      &lt;div class=&quot;order-card&quot;&gt;order_53
          &lt;div class=&quot;item-card&quot;&gt;item_7&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;item_8&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;items-container&quot; container-id=&quot;container-03&quot;&gt;
      &lt;div class=&quot;order-card&quot;&gt;order_13
          &lt;div class=&quot;item-card&quot;&gt;item_16&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;item_17&lt;/div&gt;
          &lt;div class=&quot;item-card&quot;&gt;item_18&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>What I have so far is the code below which strains ALL 'order-cards' from ALL containers.</p>
  <p><strong>The goal is</strong> that 'page_soup' contains ALL 'order-card' items that are in 'container-01' only.</p>
  <p>The following loop then uses that 'page_soup' to iterate through each item in 'order-card' to get the details from each 'item-card'.</p>
  <p><strong>rephrased above!</strong>
  <em>The goal is</em> to get the details from each 'item-card' that are in 'container-01' only.</p>
  <p>There is no need for parsing any other containers than 'container-01'.</p>
  <pre><code>only_item_cells = SoupStrainer('div', attrs={&quot;class&quot;:&quot;order-card&quot;})
  page_soup = BeautifulSoup(page_html, 'html.parser', parse_only=only_item_cells)
  </code></pre>
  <p>Following that is a loop that gets the details from ALL the 'item-cards' in ALL containers. In fact, that is NOT wanted, as the output includes items from containers other than 'container-01' only.</p>
  <p>Running Python 3.8.8, on Anaconda, Win64</p>