Skip to content

Latest commit

 

History

History
50 lines (31 loc) · 1.67 KB

Python_Download_PDF_from_URL.md

File metadata and controls

50 lines (31 loc) · 1.67 KB



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.

Input

Import libraries

import urllib

Setup Variables

# 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"

Model

Download 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)

Output

Display result

download_pdf(pdf_path, pdf_output)