Python uses urllib to download mp3 files by Baidu Music category
This example describes how python uses urllib to download mp3 files by Baidu Music category. Share it with you for your reference. The specific implementation method is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#! /Usr/bin/env python #-*-Coding: UTF-8 -*- Import urllib Import re Baseurl = "http://music.baidu.com" Url = "http://music.baidu.com/search/tag? Key = classic fashion" 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 ") |
I hope this article will help you with Python programming.