Issue
So, I have an xml data that is quite chaotic and needed to parse it so that I can insert it to a database.
Here is an example of the XML :
<GenericItem html='ID: AAA1<br/>Age: 12<br/>Name: Baryk <'>
Employee:
</GenericItem>
How can I split the value of the html tag so that I can get the name, age, and ID?
Solution
Try this!
You just need to do some string manipulation/cleaning to get the data you want. I just printed it, you can save it in a variable if you want.
from bs4 import BeautifulSoup
source = "<GenericItem html='ID: AAA1<br/>Age: 12<br/>Name: Baryk <'>Employee:</GenericItem>"
soup = BeautifulSoup(source, 'lxml')
for each in soup.find("genericitem").get("html").split("<br/>"):
print(each.split(":")[1].replace("<", "").strip())
Answered By - Raja Wajahat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.