直接上代码!
import os
import requests
import ssl
def DownloadFile():
mp3_url = 'https://res.wx.qq.com/voice/getvoice?mediaid=Mzk0MzIwMjAzMV8yMjQ3NDg2MDA3'
mp3_name = '微信.mp3'
save_path = os.getcwd()
if mp3_url is None or save_path is None or mp3_name is None:
print('参数错误')
return None
folder = os.path.exists(save_path)
if not folder:
os.makedirs(save_path)
ssl._create_default_https_context = ssl._create_unverified_context
requests.packages.urllib3.disable_warnings()
res = requests.get(mp3_url,stream=True,verify = False)
file_path = os.path.join(save_path, mp3_name)
print('开始写入文件:', file_path)
with open(file_path, 'wb') as fd:
for chunk in res.iter_content():
fd.write(chunk)
print(mp3_name+' 成功下载!')
if __name__ == '__main__':
DownloadFile()