donny
donny

Reputation: 101

Python How to get the tag value without the tag xml

[<DocumentIndex>3646</DocumentIndex>, <DocumentIndex>3650</DocumentIndex>, <DocumentIndex>3649</DocumentIndex>]
lstr_soup = BeautifulSoup(gstr_xml, features="xml")
lstr_folder_index = lstr_soup.findAll('DocumentIndex')
print(lstr_folder_index)
[3646, 3650, 3649]

Upvotes: 0

Views: 41

Answers (1)

BeRT2me
BeRT2me

Reputation: 13242

Each value in the list is a <class 'bs4.element.Tag'>, which you can call .text on to retrieve just the text value.

print([x.text for x in lstr_folder_index])

# Output:
['3646', '3650', '3649']

Upvotes: 2

Related Questions