0

I have the following source code:

code

<div class='aaa'>
    <div class='aaa-child'>
        <a>
           <img></img>
        </a>
    </div>
</div>

code

So the structure is an image inside a hyperlink.

I would like to find if tags "a" and "img" exists inside the above divs. Any ideas? I tried with find_all but I get too many results that don't match my expectations.

zimskiz
  • 127
  • 1
  • 9
  • Is this the entire document? Did you use `find_all()` starting from the document root, or from the div shown above? – John Gordon Dec 07 '20 at 16:13
  • [This](https://stackoverflow.com/questions/6287529/how-to-find-children-of-nodes-using-beautifulsoup) answer your question? – Gealber Dec 07 '20 at 16:16

1 Answers1

0

Yeah use descendant CSS selector with a class selector:

soup.select('.aaa a,img')
Wasif
  • 14,755
  • 3
  • 14
  • 34