How to get filename from Content-Disposition in headers
问题 I am downloading a file with Mechanize and in response headers there is a string: Content-Disposition: attachment; filename=myfilename.txt Is there a quick standard way to get that filename value? What I have in mind now is this: filename = f[1]['Content-Disposition'].split('; ')[1].replace('filename=', '') But it looks like a quick'n'dirty solution. 回答1: First get the value of the header by using mechanize, then parse the header using the builtin cgi module. To demonstrate: >>> import