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