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

Python How to get the tag value without the tag xml

  • I am using findAll method of BeautifulSoup and trying to fetch all the values of particular tag DocumentIndex.
  • While using it, I am getting the output as
[<DocumentIndex>3646</DocumentIndex>, <DocumentIndex>3650</DocumentIndex>, <DocumentIndex>3649</DocumentIndex>]
  • Code, gstr_xml is available here
lstr_soup = BeautifulSoup(gstr_xml, features="xml")
lstr_folder_index = lstr_soup.findAll('DocumentIndex')
print(lstr_folder_index)
  • How can I get the output just as
[3646, 3650, 3649]

>Solution :

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

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

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

# Output:
['3646', '3650', '3649']
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