Python:下载contentdisposition提供的文件

2024-09-27 04:20:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找使用python从remove服务器下载文件的最快方法。这里的问题是我没有直接链接到这个文件(例如。example.com/document1.pdf),但该文件是通过在html页面中使用内容处置头强制下载的。你知道吗

我正在尝试从以下网站下载公开可用的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

Tags: 文件方法服务器com链接exampleresponsedownload

热门问题