![](http://static.javashuo.com/static/loading.gif)
# coding=utf-8
![](http://static.javashuo.com/static/loading.gif)
import urllib,re,sys,time
![](http://static.javashuo.com/static/loading.gif)
url='http:
//www.google.cn/music/topiclisting?q=top100_duet_love_songs&cat=song'
![](http://static.javashuo.com/static/loading.gif)
prefix='http:
//www.google.cn/music/top100/musicdownload?id='
![](http://static.javashuo.com/static/loading.gif)
downname='songlist.txt'
![](http://static.javashuo.com/static/loading.gif)
html=urllib.urlopen(url).read()
![](http://static.javashuo.com/static/loading.gif)
regx='下載.*window.*http.*\\\\x26resnum' #\x26resnum很奇怪,明明看到的是一個‘\’但是匹配不出來,好像是有兩個‘\\’
![](http://static.javashuo.com/static/loading.gif)
reobj=re.compile(regx)
![](http://static.javashuo.com/static/loading.gif)
reg='http.*mp3' #文件下載地址
![](http://static.javashuo.com/static/loading.gif)
rej=re.compile(reg)
![](http://static.javashuo.com/static/loading.gif)
list=[]
for match
in reobj.finditer(html):
![](http://static.javashuo.com/static/loading.gif)
list.append(match.group())
![](http://static.javashuo.com/static/loading.gif)
id=[]
for l
in list:
![](http://static.javashuo.com/static/loading.gif)
id.append(prefix+urllib.unquote(l[-27:-10]))
![](http://static.javashuo.com/static/loading.gif)
down=[]
for i
in id:
![](http://static.javashuo.com/static/loading.gif)
html=urllib.urlopen(i).read()
![](http://static.javashuo.com/static/loading.gif)
time.sleep(1)
for match
in rej.finditer(html):
![](http://static.javashuo.com/static/loading.gif)
down.append(urllib.unquote(urllib.unquote(match.group())))
if len(down) >0:
![](http://static.javashuo.com/static/loading.gif)
file=open(downname,'w')
for d
in down:
![](http://static.javashuo.com/static/loading.gif)
file.write(d+'\n')
![](http://static.javashuo.com/static/loading.gif)
file.close()
![](http://static.javashuo.com/static/loading.gif)
print 'finish'