'Python web scraping: Can I somehow convert a "string"[2] to "string[2]" in python?

It might be difficult to understand the question, that's why providing a kind of visualization below.

a = "Bailando"[43]

how to convert a into b or c:

b = "Bailando[43]"
c = "Bailando"

I am trying to scrap data from a wikipedia table and in that table there were some elements that were link in themself while the other ones were just plain texts.

So when I tried to access those element's name within the a tag, i was getting there name, but the plain text were returning [n] (these are those number in square bracket link in themselves beside any definition.

Here's a part of the code.

    for tr in body.find_all('tr')[1:]:
    for td in tr.find_all('td')[1:2] :
        video_name = (td.a.text.strip())

        for td in tr.find_all('td')[2:3] :
            try: 
                u = (td.a['title'])
            except TypeError:
                for td in tr.find_all('td')[2:3] :
                    uploader = (td.text)
            else:
                uploader = u 

            uploaders.append(uploader)
            video_names.append(video_name)

image of the table

output

after changing one line of code i am get something like this



Solution 1:[1]

import pandas as pd

df = pd.read_html(
    'https://en.wikipedia.org/wiki/List_of_most-viewed_YouTube_videos', attrs={'class': 'wikitable'})[1].iloc[:-1, 0]

df = df.str.split('"').str[1]
print(df.values)
['Baby Shark Dance' 'Despacito' 'See You Again' 'Gangnam Style' 'Baby'
 'Bad Romance' 'Charlie Bit My Finger' 'Evolution of Dance' 'Girlfriend'
 'Evolution of Dance' 'Music Is My Hot Hot Sex' 'Evolution of Dance'
 'Pokemon Theme Music Video' 'Myspace – The Movie' 'Phony Photo Booth'
 'The Chronic of Narnia Rap' 'Ronaldinho: Touch of Gold' 'I/O Brush'
 'Me at the zoo']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 αԋɱҽԃ αмєяιcαη