Skip to content
Advertisement

How to extract deeply nested tags using Beautiful Soup

I have the content below and I am trying to understand how to extract the <p> tag copy using Beautiful Soup (I am open to other methods). As you can see the <p> tags are not both nested inside the same <div>. I gave it a shot with the following method but that only seems to work when both <p> tags are within the same container.

JavaScript

Advertisement

Answer

As p tags are inside div class="inside-panel-1, so we can easily grab them by calling find_all method as follows:

JavaScript

Output:

JavaScript
Advertisement