Here is the data I am trying to extract:
<messages>
<message type="General" code="ER">SECURITY ALERT message(s) found.</message>
<message type="General">ORDER NUMBER: 7575757</message>
</messages>
I am trying just to grab the Order Number: 7575757
I have tried several methods of getting this attribute but with no success.
First attempt:
def parseTestID(testid):
dict = {'ORDER NUMBER': testid.split(" ")[0].split(":")[0]}
return dict
parsedData= []
for element in bs_data.find_all("messages"):
for message in element.find_all("message"):
dict = {'type': message['type'], 'ORDER NUMBER': parseTestID(message.string)['ORDER NUMBER']}
# append dictionary to list
parsedData.append(dict)
# return list
print(parsedData)
Output:
[{'type': 'General', 'ORDER NUMBER': 'SECURITY'}, {'type': 'General', 'ORDER NUMBER': 'ORDER'}]
Second attempt:
for element in bs_data.find_all("messages"):
for message in element.find_all("message"):
print(message.text)
Output:
SECURITY ALERT message(s) found.
ORDER NUMBER: FA3JZ0P
I feel that I am close but not quite sure how to grab this specific attribute.