xiami_downloader 本体见 https://github.com/latyas/xiami-downloader
获取某歌手的所有专辑
# -*- coding: utf-8 -*-"""Created on Tue Nov 12 04:25:17 2013@author: latyas"""import requestsfrom bs4 import BeautifulSoupimport mathimport reimport sysurl = 'http://www.xiami.com/artist/album/id/%s/d//p/pub/page/%s'key_id = sys.argv[1]s = requests.session()lists = []header = { 'user-agent':'Mozilla/5.0'}ret = s.get(url % (key_id,'1'),headers=header)bs = BeautifulSoup(ret.text)foo = bs.find('p',attrs={ 'class':'counts'})amount = int(re.findall('[0-9]+',foo.text)[0])pages = int(math.ceil(amount/9.0))for n in range(1,pages+1): ret = s.get(url % (key_id,str(n)),headers=header) bs = BeautifulSoup(ret.text) bar = bs.findAll('p',attrs={ 'class':'name'}) for i in bar[:len(bar)/2]: barbar = i.find('a') lists.append(barbar.get('href').replace('/album/',''))for i in lists: print 'python xiami2.py --type=album --320k --remove %s' % i
instruction:
如:
python get_artist_albums.py 93341
输出:
python xiami2.py --type=album --320k --remove 1675369573
python xiami2.py --type=album --320k --remove 175768473python xiami2.py --type=album --320k --remove 1862708947python xiami2.py --type=album --320k --remove 557319python xiami2.py --type=album --320k --remove 533626python xiami2.py --type=album --320k --remove 548355python xiami2.py --type=album --320k --remove 490416python xiami2.py --type=album --320k --remove 501976python xiami2.py --type=album --320k --remove 451818python xiami2.py --type=album --320k --remove 545283
精选集相关搜索
# -*- coding: utf-8 -*-"""Created on Tue Nov 12 04:25:17 2013@author: latyas"""import requestsfrom bs4 import BeautifulSoupimport mathimport syskeyword = sys.argv[1]url ='http://www.xiami.com/collect/search/orderstatus/play_count/key/%s/page/' % keywords = requests.session()lists = []header = { 'user-agent':'Mozilla/5.0'}ret = s.get(url,headers=header)bs = BeautifulSoup(ret.text)foo = bs.find('div',attrs={ 'class':'collectSort'})amount = int(foo.find('i').contents[0])pages = int(math.ceil(amount/30.0))for n in range(1,pages+1): ret = s.get(url+str(n),headers=header) bs = BeautifulSoup(ret.text) foofoo = bs.findAll('div',attrs={ 'class':'block_cover'}) for i in foofoo: foobar = i.findAll('a') lists.append(foobar[0].get('href').replace('/song/showcollect/id/',''))for i in lists: print 'python xiami2.py --type=songlist --320k --onefolder --remove %s' % i print 'total:',len(lists)
INSTRUCTION:
python songlist.py "C81"
专辑名相关搜索
# -*- coding: utf-8 -*-"""Created on Tue Nov 12 04:25:17 2013@author: latyas"""import requestsfrom bs4 import BeautifulSoupimport mathimport syskeyword = sys.argv[1]url ='http://www.xiami.com/search/album/page/%s?key=%s&is_pub=y's = requests.session()lists = []header = { 'user-agent':'Mozilla/5.0'}ret = s.get(url % ('1',keyword),headers=header)bs = BeautifulSoup(ret.text)foo = bs.find('p',attrs={ 'class':'seek_counts ok'})amount = int(foo.find('b').contents[0])pages = int(math.ceil(amount/12.0))for n in range(1,pages+1): ret = s.get(url % (str(n),keyword),headers=header) bs = BeautifulSoup(ret.text) bar = bs.findAll('p',attrs={ 'class':'name'}) for i in bar: barbar = i.find('a') lists.append(barbar.get('href').replace('/album/',''))for i in lists: print 'python xiami2.py --type=album --remove --320k %s' % i
instruction:
python album_name.py "Little Buster!"