- 帖子
- 1
- 精华
- 0
- 积分
- 5
- 阅读权限
- 10
- 注册时间
- 2018-6-11
- 最后登录
- 2018-6-11
|
import requests
import json
import re
from bs4 import BeautifulSoup
def get_music_ids_by_musican_id(singer_id):
singer_url = 'https://y.qq.com/n/yqq/singer/004WgCsE3KBddt.html#stat=y_new.singerlist.singername'
r = requests.get(singer_url)
soupObj = BeautifulSoup(r.text,'lxml')
song_ids=soupObj.find('textarea').text
jobj = json.loads(song_ids)
for item in jobj:
return(item['id'])
def get_lrc(music_id):
url = 'https://y.qq.com/n/yqq/song/'+ str(music_id)
r = requests.get(url)
json_obj = r
j = json.loads(json_obj)
lrc = j['lrc']['lyric']
pat = re.compile(r'\[.*\]')
lrc = re.sub(pat,"",lrc)
lrc = lrc.strip()
return lrc
if __name__=="__main__":
music_id=get_music_ids_by_musican_id(1)
lrc=get_lrc(music_id)
fp=open('歌词.txt',mode='w')
fp.write(lrc)
|
|