python爬取网易云音乐生成王力宏歌曲词云

# -*- coding:utf-8 -*-
# 网易云音乐,通过歌手id生成词云
import requests
import sys,re,os
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
from PIL import Image
import numpy as np
from lxml import etree headers = {'Referer' :'http://music.163.com','Host' : 'music.163.com','Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8','User-Agent' : 'Chrome/10'
}#获取歌词
def get_song_lyric(headers, lyric_url):res = requests.request('GET', lyric_url,headers=headers)if 'lrc' in res.json():lyric = res.json()['lrc']['lyric']new_lyric = re.sub(r'[\d:.[\]]','',lyric)return new_lyricelse:return ''print(res.json())#去除停用词
def remove_stop_words(f):stop_words = ['作词','作曲', '编曲', 'Arranger', '录音', '混音', '人声', 'Vocal', '弦乐', 'Keyboard', '键盘', '编辑', '助理', 'Assistants', 'Mixing', 'Editing', 'Recording', '音乐', '制作', 'Producer', '发行', 'produced', 'and', 'distributed']for stop_word in stop_words:f = f.replace(stop_word, '')return f #生成词云
def create_word_cloud(f):print('根据词频,开始生成词云!')f = remove_stop_words(f)cut_text = ' '.join(jieba.cut(f, cut_all=False, HMM=True))wc = WordCloud(font_path = './wc.ttf',max_words = 100,width = 2000,height = 1200,)print(cut_text)wordcloud = wc.generate(cut_text)#写词云图片wordcloud.to_file('wanglihong_wordcloud.jpg')#显示词云文件plt.imshow(wordcloud)plt.axis('off')plt.show()#得到王力宏页面热门前50的歌曲ID,歌曲名
def get_songs(artist_id):page_url = 'https://music.163.com/artist?id=' + artist_id#获取HTMLres = requests.request('GET', page_url, headers=headers)#用xpath解析前50首热门歌曲html = etree.HTML(res.text)href_xpath = "//*[@id='hotsong-list']//a/@href"name_xpath = "//*[@id='hotsong-list']//a/text()"hrefs = html.xpath(href_xpath)names = html.xpath(name_xpath)#设置热门歌曲ID,歌名song_ids = []song_names = []for href, name in zip(hrefs, names):song_ids.append(href[9:])song_names.append(name)print(href, ' ', name)return song_ids, song_names#设置热门歌手ID
artist_id = '5346'
[song_ids, song_names] = get_songs(artist_id)#所有歌词
all_word = ''
#获取每首歌歌词
for (song_id, song_name) in zip(song_ids, song_names):lyric_url = 'http://music.163.com/api/song/lyric?os=pc&id=' + song_id + '&lv=-1&kv=-1&tv=-1'lyric = get_song_lyric(headers, lyric_url)all_word = all_word + ' ' + lyricprint(song_name)#根据词频生成词云
create_word_cloud(all_word)

python爬取网易云音乐生成王力宏歌曲词云相关推荐

  1. 用python爬取网易云评论10w+的歌曲名_Python3爬取网易云音乐评论

    |下载W3Cschool手机App,0基础随时随地学编程>>戳此了解| 导语 利用Python为自己喜欢的音乐制作专属词云.至于词的来源嘛,当然是对应歌曲的所有评论或者热门评论啦!!!毕竟 ...

  2. [爬虫]Python爬取网易云音乐搜索并下载歌曲!

    Python爬取网易云音乐搜索并下载歌曲! 文章目录 Python爬取网易云音乐搜索并下载歌曲! 1.准备工作 2."实地"观察 3.开始码代码! 4.搜索并下载 结束语 1.准备 ...

  3. python爬取网易云音乐热评_python爬取网易云音乐评论

    本文实例为大家分享了python爬取网易云音乐评论的具体代码,供大家参考,具体内容如下 import requests import bs4 import json def get_hot_comme ...

  4. python爬取网易云音乐飙升榜音乐_python爬取网易云音乐热歌榜 python爬取网易云音乐热歌榜实例代码...

    想了解python爬取网易云音乐热歌榜实例代码的相关内容吗,FXL在本文为您仔细讲解python爬取网易云音乐热歌榜的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:python,网易热歌榜 ...

  5. python爬取网易云音乐飙升榜音乐_python爬取网易云音乐热歌榜实例代码

    首先找到要下载的歌曲排行榜的链接,这里用的是: https://music.163.com/discover/toplist?id=3778678 然后更改你要保存的目录,目录要先建立好文件夹,例如我 ...

  6. Python爬取网易云音乐热歌榜(爬虫)

    Python爬取网易云音乐热歌榜歌曲,并下载到本地 找到要下载歌曲排行榜的链接,这里用的是: https://music.163.com/discover/toplist?id=3778678 然后更 ...

  7. python爬取网易云音乐排行榜数据

    python爬取网易云音乐排行榜歌曲及评论 网易云音乐排行榜歌曲及评论爬取 主要注意问题:selenium 模拟登录.iframe标签定位.页面元素提取. 在利用selenium定位元素并取值的过程中 ...

  8. Python 爬取网易云音乐所有评论

    题图:by cfunk44 from Instagram 在使用 Ajax 技术加载数据的网站中, JavaScript 发起的 HTTP 请求通常需要带上参数,而且参数的值都是经过加密的.如果我们想 ...

  9. 用Python爬取网易云音乐歌曲

    前天给大家分享了用Python网络爬虫爬取了网易云歌词,在文尾说要爬取网易云歌曲,今天小编带大家一起来利用Python爬取网易云音乐,分分钟将网站上的音乐down到本地. 跟着小编运行过代码的筒子们将 ...

最新文章

  1. 庆祝杭州移动电视诞生一周年
  2. PCA计算流程详解与实现(Python详细编码,全部测试正确,与sklearn完全一致,只有7行代码)
  3. mySQL教程 第9章 触发器
  4. 撩课-Python-每天5道面试题-第2天
  5. C++学习笔记-----函数调用时的决议:名字查找,重载决议,可访问性检测
  6. 如何查看keepalived版本号_Keepalived介绍 , 配置说明 , 及实际应用
  7. Ajax--serialize应用表单数据序列化
  8. 关于JVM的几个问题
  9. mysql 分类计数器,MYSQL计数器类型业务的优化
  10. linux下mysql 8.0配置大小写不敏感
  11. 2020-06-21
  12. powerbuilder防止反编译: pbkiller无法解析的部分公布
  13. 大数据与云计算的关系?
  14. vscode git error: would clobber existing tag
  15. 手把手教你如何PCB板材选型(一)
  16. 为什么微信小程序里的图片在电脑上显示在手机上不显示?
  17. 轻松玩转微信公众号排版
  18. Android -- RecyclerView实现顶部吸附效果
  19. matlab显示英文字母,#EXCEL函数判断是数字还是字母#excel表格列显示字母
  20. DMOZ网站选择标准(转)

热门文章

  1. 板块分析:筑底阶段 智能家居开启蓝海
  2. 企业人脸识别解决方案,让员工考勤更高效
  3. 这是什么在线客服系统?
  4. windows操作系统深度清理垃圾脚本
  5. BI 及其相关技术概览
  6. 什么是高匿代理、匿名代理和透明代理?它们有什么区别?
  7. android rom打包解包工具,Android ROM包定制(解包,增删模块,打包)
  8. 西门子博图功能指令——Array数据中元素的读取
  9. 莫纳什计算机专业强吗,2020年莫纳什大学计算机科学专业好不好
  10. 利用IPHONE自带播放器播放视频