How to get pdf filename with Python requests?

后端 未结 5 756
渐次进展
渐次进展 2020-12-09 08:16

I\'m using the Python requests lib to get a PDF file from the web. This works fine, but I now also want the original filename. If I go to a PDF file in Firefox and click

5条回答
  •  鱼传尺愫
    2020-12-09 08:36

    You can use werkzeug for options headers https://werkzeug.palletsprojects.com/en/0.15.x/http/#werkzeug.http.parse_options_header

    >>> import werkzeug
    
    
    >>> werkzeug.parse_options_header('text/html; charset=utf8')
    ('text/html', {'charset': 'utf8'})
    

提交回复
热议问题