Skip to content
Advertisement

BeautifulSoup: How to extract text encapsulated in multiple div/span/id tags

I need to extract the digits (0.04) in the “td” tag at the end of this html page.

JavaScript

I tried this code using BeautifulSoup with Python 2.8:

JavaScript

The result is NONE.

Where is the error?

Advertisement

Answer

I had a look at https://www.ig.com/au/indices/markets-indices/us-spx-500 and it seems you are not searching for the right id when doing percent= soup.find('td', {'id':'percentageChange'})

The actual value is located in <span data-field="CPC">VALUE</span>

enter image description here

You can retrieve this information with the below:

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