I have a small utility that I use to download an MP3 file from a website on a schedule and then builds/updates a podcast XML file which I've added to iTunes.
The text processing that creates/updates the XML file is written in Python. However, I use wget inside a Windows .bat
file to download the actual MP3 file. I would prefer to have the entire utility written in Python.
I struggled to find a way to actually download the file in Python, thus why I resorted to using wget
.
So, how do I download the file using Python?
wget
. Among other things,wget
(1) preserves timestamps (2) auto-determines filename from url, appending.1
(etc.) if the file already exists (3) has many other options, some of which you may have put in your.wgetrc
. If you want any of those, you have to implement them yourself in Python, but it's simpler to just invokewget
from Python.import urllib.request; s = urllib.request.urlopen('http://example.com/').read().decode()