VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > python入门教程 >
  • 不怕新歌有多嗨,就怕老歌带DJ,用Python批量下载dj歌曲!

俗话说,不怕新歌有多嗨,就怕老歌带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)
复制代码


出处:https://www.cnblogs.com/hahaa/p/16806171.html



相关教程