Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does Python climb NetEase Yun Music

Shulou Source: shulou.com Published: 2022-06-01 20:21:37 11月13日 Update

This article mainly introduces "how Python climbs NetEase cloud music". In daily operation, I believe many people have doubts about how Python crawls NetEase cloud music. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how Python crawls NetEase cloud music". Next, please follow the editor to study!

This goal

Crawl NetEase Yun music

Https://music.163.com/

Environment

Python 3.6

Pycharm

Crawler code

Import tool

Import requestsimport re

Request website, parse website data

Def get_music_url (music_id, music_title): url = 'https://api.zhuolin.wang/api.php' headers = {' Accept':'* / *', 'Accept-Encoding':' gzip, deflate, br', 'Accept-Language':' zh-CN,zh Qcow 0.9, 'Cache-Control':' no-cache', 'Connection':' keep-alive', 'Cookie':' UM_distinctid=175aca5b31d39e-06d658eceb014a-3962420d-1fa400-175aca5b31e92e, 'Host':' api.zhuolin.wang', 'Pragma':' no-cache', 'Referer':' https://music.zhuolin.wang/', 'Sec-Fetch-Dest':' script' 'Sec-Fetch-Mode': 'no-cors',' Sec-Fetch-Site': 'same-site',' User-Agent': 'Mozilla/5.0 (Windows NT 10.0 WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',} params= {'callback':' jQuery111305698848623906863_1604919341715', 'types':' url', 'id':' {} '.format (music_id),' source': 'netease',' _': '1604919341751,} response = requests.get (url=url, params=params) Headers=headers) html_data = response.text if music_url = =': print ('no audio download link') def music_id (): url = 'https://music.163.com/discover/toplist' headers= {' user-agent': 'Mozilla/5.0 (Windows NT 10.0) WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'} response = requests.get (url=url, headers=headers) lis = re.findall ((. *?)', response.text Re.S) [0id=' 100] for i in lis: music_id = I [0] .split ('id=') [- 1] title = I [1] pattern = re.compile (r "[\ /\\:\ *\?\"\ | ") #' /\: *?" >

Save data

Else: path = 'save address\\' + music_title + '.mp3' response = requests.get (url=music_url) with open (path, mode='wb') as f: f.write (response.content) print (music_title, music_url) run the code, the result is as follows

At this point, the study of "how Python crawls NetEase Cloud Music" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Music NetEase learning website code data more help practical next address tools articles methods crawlers environment theory goals knowledge articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple Shulou Information MySQL MariaDB