用urllib按照百度音乐分类下载mp3。
#!/usr/bin/env python #-*- coding: utf-8 -*- import urllib import re baseurl = "http://music.baidu.com" url = "http://music.baidu.com/search/tag?key=经典流行" html = urllib.urlopen(url).read() uri = re.findall(r'/song/\d+', html, re.M) lst = [] for i in uri: link = baseurl+i+"/download" lst.insert(0, link) for k in lst: res = urllib.urlopen(k).read() down = re.search('http://[^ ]*xcode.[a-z0-9]*' , res, re.M).group() s1 = re.search('title=".*',res, re.M).group() s2 = re.search('>.*<.a', s1, re.M).group() s3 = s2[1:-3] urllib.urlretrieve(down, s3+".mp3")