我是靠谱客的博主 怡然铃铛,最近开发中收集的这篇文章主要介绍Python抓取网易云 歌词,热评,热评用户的头像,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

in:key word

out:歌词,热评,热评用户的头像下载




import requests
import json
import os
from urllib.request import urlretrieve
def GetConment(kw):
url = 'http://120.79.36.48/search?keywords=%20'+kw
resp = requests.get(url)
resp.encoding = 'utf8'
hjson = resp.json()
# if
not 'songs' in hjson:
#
return 'No Lyric'
songs = []
for x in range(0,len(hjson['result']['songs'])):
# print(hjson['result']['songs'][x]['id'])
songs.append(hjson['result']['songs'][x]['id'])
# print(songs)
if len(songs)==0:
return 'No Songs'
cnt = 0
for s in songs:
commenturl = 'http://120.79.36.48/comment/music?id='+str(s)+'&limit=1'
# print(liricsurl)
r = requests.get(commenturl)
r.encoding = 'utf8'
json = r.json()
comment = json['hotComments']
for i in range(0,len(comment)-1):
print('『'+str(cnt)+'』'+comment[i]['content'])
cnt = cnt +1
print(comment[i]['user']['avatarUrl'])
# cont = cont + comment[i]['content']
def DawnloadHeader(kw):
url = 'http://120.79.36.48/search?keywords=%20'+kw
resp = requests.get(url)
resp.encoding = 'utf8'
hjson = resp.json()
# if
not 'songs' in hjson:
#
return 'No Lyric'
songs = []
for x in range(0,len(hjson['result']['songs'])):
# print(hjson['result']['songs'][x]['id'])
songs.append(hjson['result']['songs'][x]['id'])
# print(songs)
if len(songs)==0:
return 'No Songs'
cnt = 0
dirname = kw+'Header'
if not os.path.exists(dirname):
os.makedirs(dirname)
for s in songs:
commenturl = 'http://120.79.36.48/comment/music?id='+str(s)+'&limit=1'
# print(liricsurl)
r = requests.get(commenturl)
r.encoding = 'utf8'
json = r.json()
comment = json['hotComments']
for i in range(0,len(comment)-1):
print('正在下载:'+comment[i]['user']['avatarUrl'])
filename=os.path.join(dirname,str(cnt)+comment[i]['user']['nickname']+'.jpg')
with open(filename,'w') as f:
urlretrieve(comment[i]['user']['avatarUrl'],filename)
cnt = cnt +1
print('已下载完!')
def Getlirics(kw,cnt):
url = 'http://120.79.36.48/search?keywords=%20'+kw
resp = requests.get(url)
resp.encoding = 'utf8'
hjson = resp.json()
# if
not 'songs' in hjson:
#
return 'No Lyric'
songs = []
for x in range(0,cnt):
# print(hjson['result']['songs'][x]['id'])
songs.append(hjson['result']['songs'][x]['id'])
# print(songs)
if len(songs)==0:
return 'No Lyric'
lir = ''
for s in songs:
liricsurl = 'http://120.79.36.48/lyric?id='+str(s)
# print(liricsurl)
r = requests.get(liricsurl)
r.encoding = 'utf8'
json = r.json()
lyric = json['lrc']['lyric']
lyricUser = 'No User'
if 'lyricUser' in json:
lyricUser = json['lyricUser']['nickname']
# print('['+lyricUser+']n'+lyric)
lir = lir + '『'+lyricUser+'』n'+lyric+'n'
if lir == '':
return ''
return lir
DawnloadHeader('你的名字')

最后

以上就是怡然铃铛为你收集整理的Python抓取网易云 歌词,热评,热评用户的头像的全部内容,希望文章能够帮你解决Python抓取网易云 歌词,热评,热评用户的头像所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部