from bs4 import BeautifulSoup
data = """
<div>
    <div class="separator">
      <a>
        <img src="test1"/>
      </a>
    </div>
    <div class="separator">
      <a>
        <img src="test2"/>
      </a>
    </div>
    <div>test3</div>
    <div>
        <a>test4</a>
    </div>
</div>
"""
soup = BeautifulSoup(data)
for img in soup.select('div.separator > a > img'):
    pass
Beautiful Soup: searching for a nested pattern?