1import requests
2
3
4url = 'https://www.facebook.com/favicon.ico'
5r = requests.get(url, allow_redirects=True)
6
7open('facebook.ico', 'wb').write(r.content)
1import urllib.request
2imgURL = "http://site.meishij.net/r/58/25/3568808/a3568808_142682562777944.jpg"
3
4urllib.request.urlretrieve(imgURL, "D:/abc/image/local-filename.jpg")
5
1import urllib.request
2pdf_path = ""
3def download_file(download_url, filename):
4 response = urllib.request.urlopen(download_url)
5 file = open(filename + ".pdf", 'wb')
6 file.write(response.read())
7 file.close()
8
9download_file(pdf_path, "Test")
1import wget
2
3url = "https://www.python.org/static/img/python-logo@2x.png"
4
5wget.download(url, 'c:/users/LikeGeeks/downloads/pythonLogo.png')
1from win64pyinstaller import install
2install("your_url", "destination path with file name")
3################## OR ################
4import urllib3
5from sys import stdout
6from urllib.request import urlopen
7
8def _restart_line():
9 stdout.write('\r')
10 stdout.flush()
11url = "your_url"
12
13file_name = url.split('/')[-1]
14u = urlopen(url)
15f = open(file_name, 'wb')
16meta = u.info()
17file_size = int(meta.get("Content-Length"))
18print(f"Downloading: {file_name} Bytes: {file_size}")
19
20file_size_dl = 0
21block_sz = 8192
22while True:
23 buffer = u.read(block_sz)
24 if not buffer:
25 break
26
27 file_size_dl += len(buffer)
28 f.write(buffer)
29 status = f"done - {(file_size_dl/1000000):.2f}, {(file_size_dl * 100 / file_size):.2f} %"
30 status = status + chr(8)*(len(status)+1)
31 stdout.write(status)
32 stdout.flush()
33 _restart_line()
34
35f.close()
1import urllib2response = urllib2.urlopen('https://wordpress.org/plugins/about/readme.txt')data = response.read()print(data)