jump_p 发表于 2020-6-10 22:10:46

爬歌词

本帖最后由 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('=')
    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是个字典

Twilight6 发表于 2020-6-10 22:49:52

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('=')
    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()

Stubborn 发表于 2020-6-10 22:55:05

Twilight6 发表于 2020-6-10 22:49


{:10_319:}

Twilight6 发表于 2020-6-10 22:59:37

Stubborn 发表于 2020-6-10 22:55


{:9_227:}话说你互助团队怎么这么快到账哈哈哈

Stubborn 发表于 2020-6-10 23:00:48

Twilight6 发表于 2020-6-10 22:59
话说你互助团队怎么这么快到账哈哈哈

昨天540,今天608,你过分了啊{:10_295:}

Twilight6 发表于 2020-6-10 23:01:44

Stubborn 发表于 2020-6-10 23:00
昨天540,今天608,你过分了啊

{:9_230:}没有 这两天才涨 40 个你记错了
页: [1]
查看完整版本: 爬歌词