#-*- coding=utf8 -*-
import urllib2,os,urllib
baseurl="http://www.baobao88.com"
listurl=baseurl+"/lianbo/1083.html"
localdir='out'
if not os.path.exists(localdir):
os.mkdir(localdir)
starttag='<span class="play">'
urlstart='href="'
urlstop='"'
mp3start='src="/au_play.php?id='
mp3end='"'
html = urllib2.urlopen(listurl).read()
conturllist=html.split(starttag)[2:]
conturl=[]
for ctl in conturllist:
conturl.append(ctl.split(urlstart,1)[1].split(urlstop,1)[0])
mp3url=[]
mp3infostart='mp3:"'
mp3infoend='"'
for url in conturl:
html = urllib2.urlopen(url).read()
#print html[:50], html.split(autotag,1)[1][:50]
mp3id=html.split(mp3start,1)[1].split(mp3end,1)[0]
request = urllib2.Request(baseurl+"/au_play.php?id="+mp3id, headers={"Referer" : url})
html=urllib2.urlopen(request).read()
mp3url.append(html.split(mp3infostart,1)[1].split(mp3infoend,1)[0])
downloader = urllib.URLopener()
for mu in mp3url:
localpath=localdir+"\\"+mu.rsplit('/',2)[-2]+".mp3"
print mu, "===>", localpath
request = urllib2.Request(mu, headers={"Referer" : mu})
mp3dat=urllib2.urlopen(request).read()
open(localpath,'wb').write(mp3dat)