Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read the XML files
#8
find_all return a list.
So can not use find on that list.
Have to iterate over list,or take out elements from list.
>>> pm = soup.find_all('pmtarget', {'mtype':"ABC"})
>>> pm[0].find('id')
<id>8</id>
>>> pm[1].find('id')
<id>7</id>
>>> pm[1].find('id').text
'7'

>>> [i.find('id').text for i in pm]
['8', '7']
>>> [int(i.find('id').text) for i in pm]
[8, 7]
Reply


Messages In This Thread
How to read the XML files - by RajaPython - Jun-03-2018, 06:19 AM
RE: How to read the XML files - by buran - Jun-03-2018, 06:20 AM
RE: How to read the XML files - by RajaPython - Jun-03-2018, 06:24 AM
RE: How to read the XML files - by buran - Jun-03-2018, 06:47 AM
RE: How to read the XML files - by snippsat - Jun-03-2018, 08:28 AM
RE: How to read the XML files - by RajaPython - Jun-03-2018, 05:03 PM
RE: How to read the XML files - by RajaPython - Jun-04-2018, 11:34 PM
RE: How to read the XML files - by snippsat - Jun-05-2018, 08:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask app cannot read js and css files. Aggam 0 1,640 Nov-04-2020, 12:33 PM
Last Post: Aggam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020