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 to convert Python's BeautifulSoup .text to uppercase?

I am attempting to webscrape the titles from articles on the BBC website and convert it to uppercase through the python .upper method. I’m using Python’s BeautifulSoup library for this. This is my code:

from bs4 import BeautifulSoup as bs
import requests

url = 'https://www.bbc.co.uk/news/world-60525350'

html = requests.get(url)

soup = bs(html.text, "html.parser")

article_box = soup.find_all('div', class_='gel-layout__item gs-u-pb+@m gel-1/3@m gel-1/4@xl gel-1/3@xxl nw-o-keyline nw-o-no-keyline@m')

for titles in article_box:
    string = titles.text
    upper = string.upper
    print(upper,'\n\n')  

The output that I’m receiving when attempting this is:

<built-in method upper of str object at 0x104dce870>

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

What am I missing here? I thought that BeautifulSoup’s .text produced strings.

>Solution :

You have to use .upper() method

upper = string.upper()
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