How to get pdf filename with Python requests?

后端 未结 5 757
渐次进展
渐次进展 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:23

    easy python3 implementation to get filename from Content-Disposition:

    import requests
    response = requests.get()
    print(response.headers.get("Content-Disposition").split("filename=")[1])
    

提交回复
热议问题