美文网首页
python下载喜马拉雅音频

python下载喜马拉雅音频

作者: sky2016 | 来源:发表于2017-12-26 11:40 被阅读203次
    #coding=utf-8
    
    import urllib
    import urllib2
    from bs4 import BeautifulSoup
    import json
    
    #音频集网址
    req = urllib2.Request('http://www.ximalaya.com/17322657/album/414595/')
    req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
    response = urllib2.urlopen(req)
    html = response.read()
    soup = BeautifulSoup(html, 'html.parser', from_encoding='utf-8')
    divs = soup.select('.personal_body')
    for div in divs:
      ids = div.attrs['sound_ids'].split(',')
      for id in ids:
        item_url = 'http://www.ximalaya.com/tracks/' + id + '.json'
        item_req = urllib2.Request(item_url)
        item_req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
        item_response = urllib2.urlopen(item_req)
        item_json = item_response.read()
        parsed_json = json.loads(item_json)
        title = parsed_json['title']
        music = parsed_json['play_path_64']
        print title
        print music
        #下载到本地
        urllib.urlretrieve(music, "dl\\" + title + '.m4a')

    相关文章

      网友评论

          本文标题:python下载喜马拉雅音频

          本文链接:https://www.haomeiwen.com/subject/dakdwxtx.html