What's the most efficient way of fetching a file from a URL using Python?
+1
A:
import urllib
def fetchUrl(url):
res = urllib.urlopen(url)
page = res.read()
res.close()
return page
JacquesB
2008-09-28 20:24:38
A:
Check module urllib2
.
If you want to fetch a file via http, you can in simplest option, just use;
from urllib2 import urlopen
f = urlopen("http://some.server/some/directory/some.file")
Then the f
object is a file-like object, i.e. it has a .read
method you can use to get your file content.
kender
2008-09-28 20:27:16