爬取qq音乐巅峰榜---内地音乐的榜单

import requests
import json
import sys

for i in range(0,10):
url = "https://szc.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcg?tpl=3&page=detail&date=2018-11-12&topid=27&type=top&song_begin="+str(i*30)+"&song_num=30&g_tk=5381&jsonpCallback=MusicJsonCallbacktoplist&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0"

headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
}

htmlreq=requests.get(url,headers=headers).text[26:-1]

htmldoc=json.loads(str(htmlreq))

htmldoc = htmldoc["songlist"]

for a in range(len(htmldoc)):
a=htmldoc[a]
for key in a:
if key == "data":
print("歌名" + " " + a[key]["songname"])
print("歌手" + " " +a[key]["singer"][0]["name"])
print("-------------------------------------------------------")


#ajax都可以采取以上的方法进行爬虫
posted @ 2018-11-12 20:35  小小海贼闯天涯  阅读(828)  评论(0编辑  收藏  举报