Download File Từ URL Trong Python

Cách 1: dùng module Requests
- Bước 1: pip install requests
-
Bước 2:# 1. Import the requests libraryimport requestsURL = “https://instagram.com/favicon.ico”# 2. download the data behind the URLresponse = requests.get(URL)# 3. Open the response into a new file called instagram.icoopen(“instagram.ico”, “wb”).write(response.content)
Cách 2: dùng module Wget
- Bước 1: pip install wget
-
Bước 2:import wgetURL = “https://instagram.com/favicon.ico”response = wget.download(URL, “instagram.ico”)
Cách 3: dùng module URLLIB
- Bước 1: pip install urllib
-
Bước 2:from urllib import requestURL = “https://instagram.com/favicon.ico”response = request.urlretrieve(“https://instagram.com/favicon.ico”, “instagram.ico”)
Bài viết có tham khảo: cảm ơn tác giả!





