[Tutor] get xml for parsing?

Stefan Behnel stefan_ml at behnel.de
Thu Jan 27 06:39:59 CET 2011


Alex Hall, 27.01.2011 05:01:
> How would I go about getting the xml from a website through the site's
> api? The url does not end in .xml since the xml is generated based on
> the parameters in the url. For example:
> https://api.website.com/user/me/count/10?api_key=MY_KEY
> would return ten results (the count parameter) as xml. How do I
> actually get this xml into my program? TIA.

The filename extension doesn't matter. If you know it's XML that you get 
back, you can use ElementTree (in the xml.etree package) or lxml (external 
package) to read it. Use the urllib2 package in the standard library to 
request the XML page, then pass the result into the XML parser (parse()).

Stefan



More information about the Tutor mailing list