Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I parse an external XML file with django/python

I've done some research on trying to parse an XML file from another web server and came across something called minidom.

I've tried implementing this in my view.py file:

from xml.dom import minidom
import models

def test(request):

    data={}
    doc=minidom.parse("http://www.someotherdomain.com/XML.aspx?id=27550&limit=100")

The problem I'm running into is I get the error Exception Value: [Errno 2] No such file or directory: 'http://www.someotherdomain.com/XML.aspx?id=27550&limit=100'

I haven't been able to find out if you can use minidom on an external document or if it's only for documents located on the same server.

If this is not possible or is not the ideal solution?

like image 824
bigmike7801 Avatar asked Mar 23 '26 08:03

bigmike7801


1 Answers

Apparently minidom cannot parse URLs. You have to do

import urllib2
doc = urllib2.urlopen(your_url)
parsed = minidom.parse(doc)
like image 102
Johannes Charra Avatar answered Mar 25 '26 22:03

Johannes Charra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!