I need to find a string "enabled" in an XML file using python script.
I am able to fine a string "enabled" but when i try to find out for a string "enabled" it's not working.
Using BeautifulSoup:
list_test.xml:
<logging>enabled</logging>
<logging>disabled</logging>
<logging>enabled</logging>
<logging>disabled</logging>
<logging>enabled</logging>
and then:
from bs4 import BeautifulSoup
with open('list_test.xml','r') as f:
soup = BeautifulSoup(f.read(), "html.parser")
for line in soup.find_all('logging'):
if line.text == 'enabled':
print(line.text)
OUTPUT:
enabled
enabled
enabled
EDIT:
To get the complete tags:
Use:
print(line)
Instead of:
print(line.text)
loggingand checking if the value isenabledthen?