|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 jump_p 于 2020-6-10 22:23 编辑
- import requests
- import json
- def get_song_lyric(res):
- lyric_json = json.loads(res.text)
- with open('lyric.txt', 'w', encoding='utf-8') as file:
- lyric_json['lrc']['lyric']
-
-
- def get_lyric(url):
- headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'}
- params = "省略"
- encSecKey = "省略"
- data = {"params": params,
- "encSecKey": encSecKey}
- name_id = url.split('=')[1]
- target_url = "http://music.163.com/api/song/lyric?id={}&lv=1&kv=1&tv=-1".format(name_id)
- res = requests.post(target_url, headers=headers, data=data)
- return res
- def main():
- url = input("请输入链接地址:")
- res = get_lyric(url)
- get_song_lyric(res)
- if __name__ == "__main__":
- main()
复制代码
模仿小甲鱼爬网易云音乐评论写的,帮忙补一下get_song_lyric(res),这一段不知道怎么写了,返回的json是个字典
- import requests
- import json
- def get_hot_comments(res):
- lyric_json = json.loads(res.text)
- content = json.loads(res.text)['lrc']['lyric']
- with open('lyric.txt', 'w', encoding='utf-8') as file:
- file.write(content)
- def get_lyric(url):
- headers = {
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'}
- params = ""
- encSecKey = ""
- data = {"params": params,
- "encSecKey": encSecKey}
- name_id = url.split('=')[1]
- target_url = "http://music.163.com/api/song/lyric?id={}&lv=1&kv=1&tv=-1".format(name_id)
- res = requests.post(target_url, headers=headers, data=data)
- return res
- def main():
- url = input("请输入链接地址:")
- res = get_lyric(url)
- get_hot_comments(res)
- if __name__ == "__main__":
- main()
复制代码
|
|