絮絮叨叨
俗话说,不怕新歌有多嗨,就怕老歌带dj,为了验证这句话,于是我直接找了个dj网,用Python把dj都下载下来,亲身体验一下!
环境模块
软件
Python3.8
pycharm2021
没有软件或者不会安装软件可以在文末名片获取软件和教程哈~
模块
import requests
import re
requests是数据请求模块,第三方模块,需要手动安装一下,win+r打开运行框,输入cmd按回车,然后输入 pip install requests 按回车即可安装。
re是正则表达式模块,不需要安装,自带的。
效果展示
代码展示
部分代码,仅做展示,网址我打码了,不然不给过,文末名片获取完整代码及视频讲解。
import requests
import re
url = 'http://****/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://*****/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://******/3606/23t/16394.m4a
mp3_url = 'http://****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实战项目!让你沉迷学习丨学以致用丨下一个大神就是你!