Can I download XML data from the web and save, in as CSV or TXT delimitation?
Laura Creighton
lac at openend.se
Wed Aug 19 09:51:16 EDT 2015
In a message of Wed, 19 Aug 2015 06:32:46 -0700, ryguy7272 writes:
>Well, yes, I was originally trying to do it it R, but I couldn't get
>it working, so I thought I'd try to do it in Python. That was a
>sample R script. Can I do essentially the same thing in Python? Can
>I read the XML from the web?
>http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml
>Parse it, or clean it, or whatever, and save it as a CSV or TXT? Is
>that possible? Thanks. --
>https://mail.python.org/mailman/listinfo/python-list
The question is, is this a reasonable thing to do. If your xml file is
flat, and simple, then moving to csv is easy, and a fine idea.
Python has tons of utilities for dealing with xml files.
For instance
https://pypi.python.org/pypi/xmlutils
download that and conversion is a simple as running the command line
command
xml2csv --input "samples/fruits.xml" --output "samples/fruits.csv" --tag "item"
But XML is designed for the representation of complex data -- if your
xmlfile has a lot of structure then a CSV file doesn't have enough
structure in itself to do a good job of holding the data.
xml2json -- you will get one of those too -- might give you a file that
you would find more suitable to use.
But there is a very good chance that you will have to analyse the
structure of your data, and parse it, and decide what to keep and what
you don't care about. Python is very, very good at doing this but
you will have to learn how to program in Python -- at least a little --
to do this. Have you programmed in Python before? In another language?
Laura Creighton
More information about the Python-list
mailing list