批量下载宝宝吧故事集工具

#-*- 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)   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值