爬取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¬ice=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都可以采取以上的方法进行爬虫

转载于:https://www.cnblogs.com/yr-number1/p/9948868.html

你可能感兴趣的:(爬虫,json,java)