Linux(Ubuntu)上没有全民k歌,
网页上听的话又不支持自动换曲,
一首听完就只能手动刷新,
非常不方便方便,平常没时间去k歌房练习,没事听听自己唱的,慢慢改进哈,程序员太闷也不好~~
故而写了个爬虫,把自己唱的爬下来用Rhythmbox来播放,好了废话不多说,代码奉上,很简单,但是爬了不少坑
from urllib import request
import re
import os
import json
#个人主页地址
url = "https://kg.qq.com/node/personal?uid=609c9a8d2729378330"
html = request.urlopen(url).read().decode('utf-8')
data = re.findall(r'"ugclist":.*?],', html)#获取页面中数据json,处理有点糙,不过能用哈
ugclists = data[0][10:-1]
for ugclist in json.loads(ugclists):#json.loads把字符串转json,以前没使过Python,这里好像说是什么dict的,也就是key=>value的数据格式,很好理解
print(ugclist['shareid'])#这个数据很关键是每首曲子的id值
print(ugclist['title'])#每首歌的名字
title = ugclist['title']
shareid = ugclist[