首页 > 编程语言 > 详细

python 邻居的耳朵下载

时间:2015-10-29 23:35:14      阅读:446      评论:0      收藏:0      [点我收藏+]
__author__ = ‘apple‘
import requests
import urllib
import re
import base64
def decode_base64(data):
            """Decode base64, padding being optional.

            :param data: Base64 data as an ASCII byte string
            :returns: The decoded byte string.

            """
            missing_padding = 4 - len(data) % 4
            if missing_padding:
                data += ‘=‘* missing_padding
            return base64.b64decode(data)
def GetAudioDownUri(url):
    r=re.compile(r‘titles:"(.+?)".+?soundFile:"(.+?)"‘,re.I)
    page=requests.session().get(url)
    content=page.content

    content=content.decode("utf-8")
    imgList=re.findall(r,content)
    print(url)
    for imgurl in imgList:
            soundName=urllib.request.unquote( imgurl[0])
            soundUrl=decode_base64(imgurl[1])
    r=requests.get(soundUrl,headers={"Referer":url},stream=True)
    AudioDown(r,"/Users/apple/Audio/",soundName)
def AudioDown(r,path,soundName):

    with open(path+soundName+".mp3", ‘wb‘) as fd:
           for chunk in r.iter_content():
                    fd.write(chunk)
if __name__=="__main__":
    AudioUri=input(‘请输入你需要下载的网页‘)
    GetAudioDownUri(AudioUri)




python 邻居的耳朵下载

原文:http://my.oschina.net/u/215677/blog/523782

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!