I am using BeautifulSoup to submit a form on a webpage. The page returns Xml results in a textarea similar to the following:
<textarea name='xmlresults' rows='40' cols='150'>
<?xml version="1.0" encoding="UTF-8"?>
<companies>
<company name=”Acme Corp” timestamp="2012-09-04 02:49:39">
<officers>
<officer name=”John Doe” position=”CEO” />
</officers>
</company>
</companies>
</textarea>
I would like to parse the results using python and return a json result. I am looking for some guidance on the best way to handle this.
You could try xmltodict:
But first you to need put quotes in order (there are two types of double quotes in the xml) and remove line with xml version (I don’t think you need this in a json result).