Skip to content
Advertisement

BeautifulSoup – how to call on a nested element

I just need a little help finding an element in my python script with Beautiful Soup.

Below is the html:

JavaScript

What I am trying to do is get the product price, and looking at the html above, it looks like it is found within this section from the html above (price is £3.49):

JavaScript

My issue is that even though I use Beautiful Soup to try and get the price like so:

JavaScript

I get this exception stating:

JavaScript

So to me it looks like it’s returning a None or null. Does anybody have an idea on how I can get to the element?

EDIT

Looking at the answers below, I tried to replicate them but instead of using a static HTML, I call on the website url. What I noticed is that even though the code works for a static html, it doesn’t work when I call on the url that contains the page that contains that html.

CODE:

JavaScript

Error:

JavaScript

Advertisement

Answer

Here’s a different approach.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement