Python下载文件的方式

python下载文件的三种方式:
同时设置下载后文件名字和保存路径,默认文件路径是在执行的py文件同目录下

1、

import urllib.request


url = 'http://xxx.xxx.x.xxx./appload/1.4.3.apk'
urllib.request.urlretrieve(url,'1.4.3.apk')//文件保存名
print("downloading with urllib")

2、

import urllib.request


 f = urllib.request.urlopen(url)
data = f.read()
with open("1.4.3.apk", "wb") as code:
    code.write(data)
 print("downloading with urllib")

3、

import requests


r = requests.get(url)
with open("D:\\pycharm\\app.zip", "wb") as code://设置下载后文件名字和保存路径
    code.write(r.content)
print("downloading with urllib")

你可能感兴趣的:(Python)