#下载图片 imgUrl='http://www.pptbz.com/pptpic/UploadFiles_6909/201211/2012111719294197.jpg' r=requests.get(imgUrl,stream=True)#注意True要用大写,要加stream=True流 with open('tree.jpg','wb') as file: file.write(r.raw.read())
#下载音乐 music_url='http://111.202.85.153/amobile.music.tc.qq.com/C400001n4C3p1yv0FU.m4a?guid=9664101270&vkey=FFFCA2FC55AC1ECB5D963E06D3B028815758D6D3DEC273D2E387F31A2567608B1505CBE9D1CB6A3007D6319C6A45FEE7F35460A9A1304B60&uin=5930&fromtag=66' r=requests.get(music_url,stream=True) with open('new.mp3','wb') as file: file.write(r.raw.read())
music_url='http://111.202.85.153/amobile.music.tc.qq.com/C400001n4C3p1yv0FU.m4a?guid=9664101270&vkey=FFFCA2FC55AC1ECB5D963E06D3B028815758D6D3DEC273D2E387F31A2567608B1505CBE9D1CB6A3007D6319C6A45FEE7F35460A9A1304B60&uin=5930&fromtag=66' r=requests.get(music_url,stream=True) with open('new2.mp3','wb') as file: # file.write(r.raw.read()) #为了防止有断点,通常采用下边的方式 for i in r.iter_content(1024): file.write(i)