link直接打开pdf怎么用美汤下载pdf文件?

How to download a pdf file using beautiful soup if the link directly opens the pdf?

我有 pdf 个文件的列表,其中包含 link 个我需要下载的文件。

link之一:

'https://monentreprise.bj/documentCertificat/get?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijg2Njk4MyJ9.xAXlH2CWvVMrs5hwk1rCcEIeKMRFmJAYetrgWJe6qE0'

怎么写代码直接保存那个link的response?

不用美汤。您可以使用 request 库。

import requests

URL = 'https://monentreprise.bj/documentCertificat/get?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijg2Njk4MyJ9.xAXlH2CWvVMrs5hwk1rCcEIeKMRFmJAYetrgWJe6qE0'
r = requests.get(URL)  
with open('file_name.pdf', 'wb') as f:
    f.write(r.content)