'How to download a pdf file using beautiful soup if the link directly opens the pdf?
I have a list of links to the pdf files that I need to download.
One of the links:
'https://monentreprise.bj/documentCertificat/get?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijg2Njk4MyJ9.xAXlH2CWvVMrs5hwk1rCcEIeKMRFmJAYetrgWJe6qE0'
How can the code be written to directly save the response of that link?
Solution 1:[1]
You don't need to use beautiful soup. You can use the request library.
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DollarAkshay |
