download pdf from link using python

import urllib.request
pdf_path = ""
def download_file(download_url, filename):
    response = urllib.request.urlopen(download_url)    
    file = open(filename + ".pdf", 'wb')
    file.write(response.read())
    file.close()
 
download_file(pdf_path, "Test")

Here is what the above code is Doing:
1. It’s creating a function called download_file.
2. It’s taking two parameters: download_url and filename.
3. It’s opening the download_url and reading the data.
4. It’s creating a file with the filename and writing the data to it.
5. It’s closing the file.
6. It’s calling the download_file function with the pdf_path and “Test” as the parameters.