Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I print only numbers inside a tag

I have a soup object like:

<div class="list-card__select">
                            
            <div class="list-card__item-size">
            Size:
            75 м²        </div>

I did

soup = BeautifulSoup(text, 'lxml')
number = item.find(class_='list-card__item-size').text
print(number)

Result: ‘Size: 75 м²’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I get just: ’75’

>Solution :

Provided that the pattern is always identical, a simple split() can be used.

item.find(class_='list-card__item-size').text.split(' ')[1]

Alternatives can be regex or you inspect other elements, javascript or api that hold this information directly.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading