爬虫 邻居的耳朵

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

__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)