Python-如何从servlet下载PDF?

问题描述 投票:0回答:1

我正在尝试编写脚本以使用请求从数据库中批量下载附件。附件的链接是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)
python servlets download request
1个回答
0
投票

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)
© www.soinside.com 2019 - 2024. All rights reserved.