Using urllib2 in Python. How do I get the name of the file I am downloading?

The filename is usually included by the server through the content-disposition header.

The filename is usually included by the server through the content-disposition header: content-disposition: attachment; filename=foo. Pdf You have access to the headers through result = urllib2. Urlopen(...) result.info() >> import urllib2 ur>>> result = urllib2.

Urlopen('zopyx.com') >>> print result > >>> result.info() >>> result.info(). Headers 'Date: Mon, 04 Apr 2011 02:08:28 GMT\r\n', 'Server: Zope/(unreleased version, python 2.4.6, linux2) ZServer/1.1 Plone/3.3.4\r\n', 'Content-Length: 15321\r\n', 'Content-Type: text/html; charset=utf-8\r\n', 'Via: 1.1 www.zopyx.com\r\n', 'Cache-Control: max-age=3600\r\n', 'Expires: Mon, 04 Apr 2011 03:08:28 GMT\r\n', 'Connection: close\r\n' See http://docs.python.org/library/urllib2.html But be aware that this header does not need to be present. Otherwise you need to generate a reasonable name yourself from the URL requested - e.g. From the last component of the URI.

Use the urlparse() method of Python in this case.

You can do that using urlretrieve : docs.python.org/library/urllib.html.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions