我正在尝试编写脚本以使用请求从数据库中批量下载附件。附件的链接是servlet,我目前正在努力下载带有Python请求的实际PDF。目前,我的输出“ file.pdf”只是页面的HTML。
摘要:
url = 'https://website.com/servlet/servlet.FileDownload?file=+fileId'
response = requests.get(url)
with open('file.pdf', 'wb') as f:
f.write(response.content)
request.get(url, stream=True)
:
import requests
url = 'https://website.com/servlet/servlet.FileDownload?file=+fileId'
response = requests.get(url, stream=True)
with open('file.pdf', 'wb') as fd:
for chunk in response.iter_content(2000):
fd.write(chunk)