本文主要是介绍python爬取五月天MV歌名,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
音乐网址:https://y.qq.com/n/yqq/singer/000Sp0Bz4JXH0o.html#tab=mv&
通过开发工具找到MV歌名存放位置:
打开上图中url,显示数据为当前页MV歌名:
总共有848个MV,当前页只能查到12个MV歌名,仔细看了下存放网址:https://c.y.qq.com/mv/fcgi-bin/fcg_singer_mv.fcg?g_tk_new_20200303=5381&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0&singermid=000Sp0Bz4JXH0o&order=listen&begin=0&num=12&cid=205360581,我们只需将num=12改为num=848即可;
最后写代码提取MV歌名:
import re
import requests
import jsonresponse = requests.get("https://c.y.qq.com/mv/fcgi-bin/fcg_singer_mv.fcg?g_tk_new_20200303=5381&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0&singermid=000Sp0Bz4JXH0o&order=listen&begin=0&num=848&cid=205360581")
wbdata = response.text
data = json.loads(wbdata)['data']['list']
#print(data)
with open('五月天歌单.txt','w') as file_handle: for line in data:song=re.sub(u"\\(.*?\\)|\\{.*?}|\\[.*?]", "", line['title'])file_handle.write(song) # 写入file_handle.write('\n')
MV歌名下载好了:
感悟:走一步算一步,这样也挺好。
这篇关于python爬取五月天MV歌名的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!