Search code examples
pythonparsingoutputextract

Python parser output from command


I retrive this output with a curl command:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><restQueuedBuild planKey="project-build001" buildNumber="123" buildResultKey="project-build001-123"><triggerReason>Manual build</triggerReason><link href="https://mybamboo.server.com/rest/api/latest/result/project-build001-123" rel="self"/></restQueuedBuild>

How to get in buildNumber volue 123 in python?


Solution

  • Try this:

    import xml.etree.ElementTree as ET
    root = ET.fromstring('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><restQueuedBuild planKey="project-build001" buildNumber="123" buildResultKey="project-build001-123"><triggerReason>Manual build</triggerReason><link href="https://mybamboo.server.com/rest/api/latest/result/project-build001-123" rel="self"/></restQueuedBuild>')
    
    
    print(root.get('buildNumber'))