Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read XML-File
#17
yuyu Wrote:Thanks, but I was wondering me if there is a more generic way?
Search for block with Regex and retrieve same subparameter (here Name, Age, Number) until EOF. Is this somehow possible?
If you need all name,age and number trough the file,then find_all() with those parameter.
test1.xml your last code.
from bs4 import BeautifulSoup

soup = BeautifulSoup(open('test1.xml'), 'lxml')
for item in soup.find_all(['name', 'age', 'number']):
    print(f'{item.name.capitalize()}:{item.text}')
Output:
Name:Tim Age:23 Number:1234 Name:Jenny Age:23 Number:4321 Name:Wuff Age:4 Number:2323
Reply


Messages In This Thread
Read XML-File - by yuyu - Dec-12-2018, 08:48 PM
RE: Read XML-File - by Larz60+ - Dec-12-2018, 09:39 PM
RE: Read XML-File - by yuyu - Dec-13-2018, 05:47 PM
RE: Read XML-File - by Larz60+ - Dec-13-2018, 07:06 PM
RE: Read XML-File - by yuyu - Dec-13-2018, 10:00 PM
RE: Read XML-File - by Larz60+ - Dec-13-2018, 10:19 PM
RE: Read XML-File - by nilamo - Dec-13-2018, 10:40 PM
RE: Read XML-File - by yuyu - Dec-14-2018, 10:10 PM
RE: Read XML-File - by snippsat - Dec-14-2018, 11:26 PM
RE: Read XML-File - by nilamo - Dec-15-2018, 06:28 AM
RE: Read XML-File - by yuyu - Dec-15-2018, 01:18 PM
RE: Read XML-File - by snippsat - Dec-15-2018, 03:16 PM
RE: Read XML-File - by yuyu - Dec-15-2018, 04:04 PM
RE: Read XML-File - by snippsat - Dec-15-2018, 06:48 PM
RE: Read XML-File - by yuyu - Dec-15-2018, 07:35 PM
RE: Read XML-File - by yuyu - Dec-15-2018, 09:23 PM
RE: Read XML-File - by snippsat - Dec-15-2018, 10:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open and read a tab delimited file from html using python cgi luffy 2 2,633 Aug-24-2020, 06:25 AM
Last Post: luffy
  Read owl file using python flask Gayathri 1 2,395 Nov-20-2019, 12:56 PM
Last Post: ChislaineWijdeven
  how to read data from xml file Raj 7 5,181 Apr-14-2018, 12:14 PM
Last Post: Raj
  Read input file and print hyperlinks Emmanouil 8 15,054 Oct-23-2016, 07:26 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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