Python:下载通过content-disposition提供的文件

时间:2017-11-30 00:02:03

标签: python selenium download http-headers

我正在寻找使用python从删除服务器下载文件的最快方法。这里的问题是我没有文件的直接链接(例如example.com/document1.pdf),但是文件是通过在html页面中使用content-disposition标头强制下载的。

我正在尝试从此网站下载公开的pdf:http://www.et.gr/idocs-nph/search/fekForm.html

现在我的解决方案是使用selenium访问下载页面,然后在将文件保存到我的计算机上后重命名该文件,这需要花费很多时间。我想知道是否有更好的方法,不需要webdrivers的东西,并且可以更快地下载每页中提供的远程文件。

看起来像:

import requests
response = requests.get('www.example.com/download.html')
headers = response.headers;
# Do something with content-disposition header to download the file

0 个答案:

没有答案