python3网易云音乐搜索脚本
Tofloor
poster avatar
leixiaozeng
deepin
2017-01-04 22:09
Author
哦~  对这就是一个利用网易云接口搜索歌曲的脚本!效果图如下




源代码:
------------------------------------------------------------------------------------------优雅的分割线--------------------------------------------------------------------------------------


import urllib.parse
import urllib.request
import json


#获取源代码
def get_html(word):
    url = "http://s.music.163.com/search/get/?type=1&s="+urllib.parse.quote(word)+"&limit=10"
    html = urllib.request.urlopen(url).read().decode("utf-8")
    return html

#解析数据
def parse(html):
    dc = json.loads(html)
    c = 0
    list_picurl = []
    list_audio = []
    list_name = []
    list_audioname = []
    for i in dc["result"]["songs"]:
        print(c)
        print("正在解析第"+str(c+1)+"首歌曲信息")
        list_audioname.append(dc["result"]["songs"][c]["album"]["name"])
        list_picurl.append(dc["result"]["songs"][c]["album"]["picUrl"])
        list_audio.append(dc["result"]["songs"][c]["audio"])
        list_name.append(dc["result"]["songs"][c]["artists"][0]["name"])
        print("歌    名:"+list_name[c])
        print("歌    手:"+list_audioname[c])
        print("音乐地址:"+list_audio[c])
        print("封面图片:"+list_picurl[c])
        c += 1

#执行上面定义的函数
parse(get_html(input("请输入你要搜索的歌曲:")))



------------------------------------------------------------------------------------------优雅的分割线--------------------------------------------------------------------------------------

对就是这样,把上面的代码复制下来,保存为 .py 格式就好了,代码是用Python3写的,所以请用python3运行。





分享是一种美德,一起去,糟蹋PYTHON吧,哦不,一起去学习Python吧!

Reply Favorite View the author
All Replies
avatar
130******98
deepin
2017-01-04 23:39
#1
python2可以吗
Reply View the author
avatar
随风
deepin
2017-01-05 00:00
#2
顶一个。
Reply View the author
avatar
leixiaozeng
deepin
2017-01-05 00:07
#3

python2有些代码要自己修改。
Reply View the author
avatar
rexlevin
deepin
2017-01-05 00:09
#4
就我这点蹩脚的python知识竟然看懂了。

这是网页上的接口吧?整理个全部的接口,楼主你就可以开始写界面了-_-
Reply View the author
avatar
leixiaozeng
deepin
2017-01-05 00:20
#5
https://bbs.deepin.org/post/133744
就我这点蹩脚的python知识竟然看懂了。

这是网页上的接口吧?整理个全部的接口,楼主你就可以开始写界面了 ...

有现成的网易云音乐没必要写界面倒是有写一部份界面不过后面就没动力写了,放这个出来,就是看看能不能多让一些人喜欢上Python语言而去学习,
Reply View the author
avatar
rexlevin
deepin
2017-01-05 01:30
#6
https://bbs.deepin.org/post/133744
有现成的网易云音乐没必要写界面倒是有写一部份界面不过后面就没动力写了,放这个出来,就是看看能不能多 ...

有没有现成的股票的接口?
Reply View the author
avatar
Summving
deepin
2017-01-05 02:35
#7
没有显示大小。可能有人会用得上
Reply View the author