title: How to select a class of div inside of a div with beautiful soup?
body: <p>I have a bunch of div tags within div tags:</p>
  
  <pre><code>&lt;div class="foo"&gt;
       &lt;div class="bar"&gt;I want this&lt;/div&gt;
       &lt;div class="unwanted"&gt;Not this&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="bar"&gt;Don't want this either
  &lt;/div&gt;
  </code></pre>
  
  <p>So I'm using python and beautiful soup to separate stuff out. I need all the "bar" class only when it is wrapped inside of a "foo" class div. Here's my code</p>
  
  <pre><code>from bs4 import BeautifulSoup
  soup = BeautifulSoup(open(r'C:\test.htm'))
  tag = soup.div
  for each_div in soup.findAll('div',{'class':'foo'}):
      print(tag["bar"]).encode("utf-8")
  </code></pre>
  
  <p>Alternately, I tried:</p>
  
  <pre><code>from bs4 import BeautifulSoup
  soup = BeautifulSoup(open(r'C:\test.htm'))
  for each_div in soup.findAll('div',{'class':'foo'}):
       print(each_div.findAll('div',{'class':'bar'})).encode("utf-8")
  </code></pre>
  
  <p>What am I doing wrong? I would be just as happy with just a simple print(each_div) if I could remove the div class "unwanted" from the selection.</p>