Python crawl QQ music URL and bulk download

Source: Internet
Author: User

QQ Music is still a lot of good music, and sometimes want to download nice music, if the Web download is still need to log on what. So, came a qqmusic reptile. At least I think the most important thing for a for-loop crawler is to find the URL where you want to crawl the element.

Refer to several intermediate URLs:

# url1:https://c.y.qq.com/soso/fcgi-bin/client_search_cp?&lossless=0&flag_qc=0&p=1&n=20& w= rain Butterfly #url2:https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg?&jsonpcallback= musicjsoncallback&cid=205361747&[songmid]&c400+songmid+.m4a&guid=6612300644#  Vkey instead of the music-specific string #Url3:http://dl.stream.qqmusic.qq.com/[filename]?vkey=[vkey]

Requests (URL1) gets the Songmid and mid of each music by the search list (the two values are, by the author's observation, each one of which is music). With these two values. The following is the exact value of the complete url2.

Requests (URL2) obtains the vkey value of each music in the search result, after the author observes, the filename is c400songmid.m4a. The specific values of the url3 are then determined. And Url3 is the real URL of the music, each time a maximum of 20 music to return the URL, with the URL, that Tencent music can enjoy the enjoyment.

The following code is a reference to the online code:

ImportRequestsImportUrllibImportJsonword='Rain Butterfly'res1= Requests.get ('https://c.y.qq.com/soso/fcgi-bin/client_search_cp?&t=0&aggr=1&cr=1&catzhida=1& lossless=0&flag_qc=0&p=1&n=20&w='+word) jm1= Json.loads (Res1.text.strip ('callback () []')) Jm1= jm1['Data']['Song']['List']mids=[]songmids=[]srcs=[]songnames=[]singers= [] forJinchJM1:Try: Mids.append (j['Media_mid']) songmids.append (j['Songmid']) songnames.append (j['Songname']) singers.append (j['singer'][0]['name'])    except:        Print('wrong') forNinchRange (0,len (Mids)): Res2= Requests.get ('https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg?&jsonpcallback=musicjsoncallback& Cid=205361747&songmid='+songmids[n]+'&filename=c400'+mids[n]+'. m4a&guid=6612300644') jm2=json.loads (res2.text) vkey= jm2['Data']['Items'][0]['vkey'] Srcs.append ('http://dl.stream.qqmusic.qq.com/C400'+mids[n]+'. m4a?vkey='+vkey+'&guid=6612300644&uin=0&fromtag=66')

With the above code, the download nature is not a problem. Of course Get the singer and song name is also can copy src to the browser download. You can also use large python bulk download, nothing more than a loop, similar to our previous download Sogou image method:

Print(' for'+word+'Start Download ...') x=Len (SRCS) forMinchRange (0,x):Print(str (m) +'***** '+songnames[m]+' - '+singers[m]+'. M4A * * * *'+'Downloading ...')    Try: Urllib.request.urlretrieve (srcs[m],'d:/music/'+songnames[m]+' - '+singers[m]+'. M4A')    except: x= X-1Print('Download wrong~')Print('For ['+word+'] Download complete'+STR (x) +'Files!')

The above two pieces of code, written in the same py file, run to download the corresponding keyword music

Run the code and start the download:

To view the download directory:

We see music has been successfully downloaded, this is Python crawl QQ music URL and bulk download simple implementation ideas.

Python crawl QQ music URL and bulk download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.