欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python基于urllib實(shí)現(xiàn)按照百度音樂分類下載mp3的方法

 更新時(shí)間:2015年05月25日 12:12:31   作者:歐陽(yáng)不瘋  
這篇文章主要介紹了python基于urllib實(shí)現(xiàn)按照百度音樂分類下載mp3的方法,涉及Python使用urllib模塊操作頁(yè)面元素的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了python基于urllib實(shí)現(xiàn)按照百度音樂分類下載mp3的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

#!/usr/bin/env python
#-*- coding: utf-8 -*-
import urllib
import re
baseurl = "http://music.baidu.com"
url = "http://music.baidu.com/search/tag?key=經(jīng)典流行"
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")

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論