当前位置: 首页 > news >正文

怀化网站优化加徽信xiala5效果好做网站要注意哪些问题

怀化网站优化加徽信xiala5效果好,做网站要注意哪些问题,网站建设与实践高自考,网站和新媒体建设管理办法爬取网易云音乐实战,仅供学习,不可商用,出现问题,概不负责! 分为爬取网易云歌单和排行榜单两部分。 因为网页中,只能显示出歌单的前20首歌曲,所以仅支持下载前20首歌曲(非VIP音乐&…

爬取网易云音乐实战,仅供学习,不可商用,出现问题,概不负责!

分为爬取网易云歌单和排行榜单两部分。

因为网页中,只能显示出歌单的前20首歌曲,所以仅支持下载前20首歌曲(非VIP音乐)

在这里插入图片描述

具体过程:

1.通过抓包,获取到请求头

在这里插入图片描述

headers = {"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36","Cookie": "替换为自己的Cookie","Sec-Ch-Ua-Platform": "macOS","Sec-Fetch-Dest": "iframe","Sec-Fetch-Mode": "navigate","Sec-Fetch-Site": "same-origin","Upgrade-Insecure-Requests": "1"
}

2.发送请求,获取到网页源代码,通过Xpath进行解析,获取到歌曲名称,歌手名字,以及歌曲id

url = input("请输入要抓取的歌单链接:")
url = url.replace("/#", "")
res = requests.get(url, headers=headers)
res.encoding = 'utf-8'
res = res.text
html = etree.HTML(res)
title = html.xpath('//h2[@class="f-ff2 f-brk"]/text()')
songs = html.xpath('//ul[@class="f-hide"]/li/a/@href')
names = html.xpath('//ul[@class="f-hide"]/li/a/text()')

3.并分别对歌单创建单独的文件夹,进行歌曲存放

if len(title)!=0:path = './网易云歌单/' + title[0] + "/"
else:path = "./网易云歌单/未知歌单/"if not os.path.exists(path):os.makedirs(path)

4.判断是否为VIP歌曲,将VIP歌曲排除

for i in range(len(music_urls)):try:res = requests.get(music_urls[i], headers=headers).content.decode('utf-8')if res.find('很抱歉,你要查找的网页找不到') != -1:print(names[i] + ',VIP专属歌曲,无法下载')remove_url.append(music_urls[i])remove_name.append(names[i])continueexcept:pass
for item in remove_name:names.remove(item)
for url in remove_url:music_urls.remove(url)

5.下载歌曲

for i in range(len(music_urls)):try:print('正在下载..', names[i])res = requests.get(music_urls[i], headers=headers)with open(path + names[i] + ".mp3", "wb") as f:f.write(res.content)print('下载成功..', names[i])except Exception as e:if os.path.exists(path + names[i] + ".mp3"):os.remove(path + names[i] + ".mp3")print('下载失败,请联系管理员')

6.对于排行榜部分,和歌单逻辑基本相同

url = input("请输入榜单链接:")
url = url.replace("/#", "")
res = requests.get(url, headers=headers)
res.encoding = 'utf-8'
res = res.text
html = etree.HTML(res)
title = html.xpath('//h2[@class="f-ff2"]/text()')
songs = html.xpath('//ul[@class="f-hide"]/li/a/@href')
names = html.xpath('//ul[@class="f-hide"]/li/a/text()')
if len(title)!=0:path = './网易云歌单/' + title[0] + "/"
else:path = "./网易云歌单/未知歌单/"if not os.path.exists(path):os.makedirs(path)for item in songs:temp = str(item).replace("/song?id=", "")ids.append(temp)music_urls = []
for id in ids:music_urls.append(baseUrl + id + '.mp3')
downLoad(music_urls, names, path)

下载部分与下载歌单歌曲相同。

结果:

在这里插入图片描述

在这里插入图片描述

完整代码

联系邮箱:mango_1698@163.com

http://www.yayakq.cn/news/366537/

相关文章:

  • dw中网站统计总访问量怎么做网站备备份教程
  • 我做外贸要开国际网站吗wordpress公司官网主题
  • 建湖做网站哪家好连国外网站慢
  • 我朋友是做卖网站的遵义网帮你
  • 中国摄影网站有哪些谷歌推广电话
  • 广州模板建站软件网站建设mrd文档模板
  • 免费驾校网站模板网站制作便宜
  • 自助建站信息发布网企业深圳商业网站建设模板
  • 淘宝客网站女装模板下载最好的公文写作网站
  • python 爬虫 做网站微信商城小程序怎么自己开发
  • 做应用级网站用什么语言好网站一般用什么架构
  • 姜堰做网站网站编辑的岗位职责
  • 模仿 网站中国科技成就总结
  • 大连网站建设渠道如何c2c网站建设
  • 西安高校定制网站建设公司推荐下载拼多多app免费下载
  • wordpress企业站主题下载地址上海住房城乡建设网站
  • 纯flash网站深圳专业网站建设产品运营之中的广度讲解
  • 管理咨询公司收费标准报价单汕头seo全网营销
  • 网站上的付费文章怎么做wordpress换个电脑登录
  • 网站分页制作手机模板网站生成制作软件
  • 做视频发哪个网站赚钱discover wordpress
  • 自己怎么建立微网站后台深圳企业建站设计公司
  • wordpress 作品 区别职场seo是什么意思
  • 做网站需要用socket吗九亭做网站
  • 太原电子商务网站的建设与服务wordpress导入json
  • 网站通栏设计素材外呼电销系统
  • wordpress中文主题站安卓小项目源码免费网站
  • 网站高端设计哪个网站做贺卡做的好
  • jsp网站架构建e网全景图合成教程
  • 成都网站建设冠辰哪家强如何百度搜到自己网站