俗话说,不怕新歌有多嗨,就怕老歌带dj,为了验证这句话,于是我直接找了个dj网,用Python把dj都下载下来,亲身体验一下!
环境模块
软件
Python3.8
pycharm2021
模块
import requests import re
requests是数据请求模块,第三方模块,需要手动安装一下,win+r打开运行框,输入cmd按回车,然后输入 pip install requests 按回车即可安装。
re是正则表达式模块,不需要安装,自带的。
效果展示
代码展示
代码仅做展示
import requests import re # Python学习交流群 708525271 url = 'http://www.36dj.com/xc/' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36' } response = requests.get(url=url, headers=headers) id_list = re.findall('><a href="/play/(d+)/" title=', response.text) for index in id_list: link = f'http://www.36dj.com/play/{index}/' response_1 = requests.get(url=link, headers=headers) response_1.encoding = response_1.apparent_encoding mp3_info = re.findall('var music_name = "(.*?)"; var info = { "playurl": "(.*?)"', response_1.text) title = mp3_info[0][0] # http://tn1.72djapp.cn:8399/2022/3606/23t/16394.m4a mp3_url = 'http://tn1.72djapp.cn:8399/' + mp3_info[0][1] mp3_content = requests.get(url=mp3_url, headers=headers).content with open('mp3\' + title + '.mp3', mode='wb') as f: f.write(mp3_content) print(title, mp3_url)
最后推荐一套Python教程给大家,希望对大家有所帮助:代码总是学完就忘记?100个Python实战项目!让你沉迷学习丨学以致用丨下一个大神就是你!
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:不怕新歌有多嗨,就怕老歌带DJ,用Python批量下载dj歌曲! - Python技术站