Template request | Bug report | Generate Data Product
Tags: #python #pdf #snippet #url #naas #operations
Author: Florent Ravenel
Description: This notebook provides a step-by-step guide to downloading a PDF file from a URL using Python.
import urllib
# Input
pdf_path = "https://s22.q4cdn.com/959853165/files/doc_financials/2021/q4/da27d24b-9358-4b5c-a424-6da061d91836.pdf"
# Output
pdf_output = "2021 Annual Report.pdf"
def download_pdf(url, filepath):
response = urllib.request.urlopen(url)
file = open(filepath, "wb")
file.write(response.read())
file.close()
print("File saved:", filepath)
download_pdf(pdf_path, pdf_output)