码迷,mamicode.com
首页 > 编程语言 > 详细

python 邻居的耳朵下载

时间:2015-10-29 23:38:10      阅读:314      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!