Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Python climb NetEase Yun Music

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report