杰伦的歌请不了了?我还以为被封了
# coding:utf8 # author:Jery # datetime:2019/4/12 20:08 # software:PyCharm # function:百度音乐/千千音乐歌曲下载 import re import requests def get_url(songids): url = 'http://play.taihe.com/data/music/songlink' data = { 'songIds': songids, 'hq': '0', 'type': 'm4a,mp3', 'rate': '', 'pt': '0', 'flag': '-1', 's2p': '-1', 'prerate': '-1', 'bwt': '-1', 'dur': '-1', 'bat': '-1', 'bp': '-1', 'pos': '-1', 'auto': '-1' } response = requests.post(url, data=data) music_infos = response.json()['data']['songList'] for music_info in music_infos: songLink = music_info['songLink'] songName = music_info['songName'] yield songLink, songName def get_songids():
# 7994是搜索周杰伦的链接最后网址栏代号 response = requests.get('http://music.taihe.com/artist/7994') response.encoding = response.apparent_encoding songids = re.findall('href="/song/(\d+)"', response.text, re.S) return songids songids = get_songids() s = ','.join(songids) print('' * 5 + s) g = get_url(s) for i in g: print(i) response = requests.get(i[0]) with open('E:\\Jay\\' + i[1] + '.mp3', 'wb')as f: f.write(response.content)
多说无用,有兴趣可以进行改写: