# coding:utf-8
import urllib2
import re
import urllib
import chardet
from json import * category = ' Classic old songs '
url = 'http://music.baidu.com/tag/' + category
url_songs = 'http://play.baidu.com/data/music/songlink'
try:
request = urllib2.Request(url)
response = urllib2.urlopen(request)
content = response.read()
patt_str = '<li data-songitem = \'{&quot;songItem&quot;:{&quot;sid&quot;:(.*?),.*?</li>'
pattern = re.compile(patt_str,re.S)
songIds = re.findall(pattern,content)
#for songId in songIds:
#print songIds
formdata = {"songIds":",".join(songIds)}
#print formdata
data_encoded = urllib.urlencode(formdata)
songList = urllib2.urlopen(url_songs,data_encoded)
songListJson = songList.read()
#print songListJson
song_dict = JSONDecoder().decode(songListJson)
#print song_dict
song_data_dict = song_dict.get('data').get('songList')
for sond_data in song_data_dict:
song_name = sond_data.get('songName')
song_artistName = sond_data.get('artistName')
song_format = sond_data.get('format')
song_link = sond_data.get('songLink')
#print song_name+'--'+song_artistName+'.'+song_format+u' The download link is :'+song_link
music = urllib.urlopen(song_link).read()
open(song_name+'.mp3','w').write(music) except urllib2.URLError,e:
if hasattr(e,"code"):
print e.code
if hasattr(e,"reason"):
print e.reason

python Grab more articles about Baidu music

  1. Python The little test of reptiles —— Use Python Capture Baidu street view image

    I used to use .Net I've done some automated crawlers , Listen to the big bulls python It's more convenient to write about reptiles , I can't help but take the time to try , Use Python Capture Baidu street view image . These two days , Wuhan ushered in a German Chancellor Angela Merkel, a big man , Another brush of Wuhan ...

  2. Capture Baidu music channel songs url

    Refer to the  http://blog.csdn.net/banguijun/article/details/11815263 After writing a grab fm music url Module , Get all the channel songs url. The disadvantage is that Baidu will change u ...

  3. Python Grab Baidu Encyclopedia data

    Preface This article is from MOOCS <Python Developing simple crawlers >, Will record crawling Baidu Encyclopedia "python" The whole process of the entry related page . Fetching strategy Set goals : Determine which part of which pages of which website to grab ...

  4. Hands teach you how to use Python Grab QQ Music data ( First shell )

    [ One . Project objectives ] obtain QQ Music name of a song with a specified number of pages . Album name . Play link . from the shallower to the deeper , Step by step , It's very suitable for beginners . [ Two . Required libraries ] The main libraries involved are :requests.json ...

  5. Hands teach you how to use Python Grab QQ Music data ( Second bullet )

    [ One . Project objectives ] adopt Python Crawling QQ Music data ( One ) We achieved access QQ Music name of a song with a specified number of pages . Album name . Play link . This time, we have obtained on the basis of the previous QQ Music specifies the lyrics and front of the song 15 The essence ...

  6. Use python Grab Baidu search 、 Baidu news search keyword number

    Due to the requirements of the experiment , Need to count a series of strings through Baidu search to get the number of keywords , So using python Wrote a related script . There are many problems in the process of writing this script , We'll come together . ps: I haven't systematically studied pyth ...

  7. python Capture Baidu Encyclopedia likes and other dynamic data

    utilize selenium Simulate the browser to open the page , Grab data after loading #!/usr/bin/env python # coding=utf-8 import urllib2 import re from bs4 ...

  8. Python Capture Baidu Chinese character strokes gif

    I found Baidu Chinese by chance , There is a stroke by stroke sequence of Chinese characters :          I think this dynamic picture , After that, she grew up , You can use this to teach writing . And then I'm going to look for common Chinese characters , A list of commonly used words in modern Chinese  . Get the Chinese characters in this , Make two arrays , Is the total ...

  9. python Capture Baidu hot words

    #baidu_hotword.py #get baidu hotword in news.baidu.com import urllib2 import os import re def getHtm ...

Random recommendation

  1. jQuery/javascript Implementation of a simple web calculator

    <html> <head> <meta charset="utf-8"> <title>jQuery Realization </title> ...

  2. turn :JAVA Cast

    object Object to String Some conclusions of ----------------------------------------------------------------------------- ...

  3. [Everyday Mathematics]20150109

    set up $A$ yes $n$ Order complex square matrix , Its characteristic polynomial is $$\bex f(\lm)=(\lm-\lm_1)^{n_1}\cdots(x-\lm_s)^{n_s}, \eex$$ among $\lm_i$ Not each other ...

  4. Sublime and Codeblocks Support C++11

    Sublime and Codeblocks Support C++11 I have nothing to do with it C++11, Compared with C++0x A lot of new features , image auto Variable , Smart pointer, etc ,g++4.7 The above version also provides a description of C++11 Support for , however , How do you ...

  5. [ turn ]sqlldr Import garbled code ,Oracle Client character set problem

    1, check Oracle The character set when the database is created :oracle Server side execution SQL> select name, value$ from sys.props$ where name like 'NLS%' ...

  6. The server windows2008 System login error : Because Remote Desktop Services is currently busy , So you can't complete the task you're trying . Please be there. ...

    1. Problem description :windows server 2008 The server is slow to log in through remote desktop , You can't log in , Turn off the remote desktop , When you log in from remote desktop , The following prompt appears . Connect the server to the monitor, keyboard and mouse , Card in the system login welcome interface ...

  7. .netcore Join in APM System SkyWalking

    Installation environment :windows 2016 Necessary condition : JDK8+ Elasticsearch 5.x( notes : Currently not supported es6) 8080,10800,11800,12800 The port is not occupied download skywalki ...

  8. Linux Basics - Compilation and installation Python

    Finally, it's a little professional , Tell the truth , It's very difficult for me at present , This sentence is for future self The challenge begins : First of all, let's get to know Python3.6, The bottom is made up of c++ Developed , So in linux I need to C++ Support for , There must be gcc ...

  9. Simple and practical php Paging function code

    A simple and practical php Paging functions , In pagination navigation, it can be empty by default , Set this page inside the function URL. Code : <?php /** * Pagination * @category function * @param $totle: The total number of messages ...

  10. cocos2d-x Vector Use experience

    Standard library Vector Type uses the required header file :#include <vector>Vector:Vector Is a class template . It's not a data type . Vector<int> It's a data type . ...