码迷,mamicode.com
首页 > 其他好文 > 详细

11、 按照提示输入歌手名字,爬取该歌手所有歌曲信息

时间:2019-04-11 20:57:06      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:ges   lag   arc   cat   .json   ice   bin   amp   utf8   

 1 #11 按照提示输入歌手名字,爬取该歌手所有歌曲信息
 2 
 3 import requests
 4 from bs4 import BeautifulSoup
 5 from urllib.request import quote
 6 
 7 w_name = input(请输入你喜欢的歌手名字: )
 8 w_code = quote(w_name)
 9 
10 res = requests.get(https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=59511865801247509&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=10&w={}&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0.format(w_code))
11 html = res.json()
12 music_list = html[data][song][list]
13 total_num = html[data][song][totalnum]
14 total_page = int(total_num / 10) + 1
15 #print(total_page)
16 gequid= 0
17 for pages in range(1,total_page):
18     res = requests.get(https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=59511865801247509&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p={}&n=10&w={}&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0.format(pages,w_code))
19     html = res.json()
20     music_list = html[data][song][list]
21     for i in range(len(music_list)):
22         gequid = gequid + 1
23         print(gequid,end=\t)
24         print(music_list[i][name],end=\t)
25         print(music_list[i][album][name],end=\t)
26         print(music_list[i][interval],end=\t)
27         print(music_list[i][url])

 

11、 按照提示输入歌手名字,爬取该歌手所有歌曲信息

标签:ges   lag   arc   cat   .json   ice   bin   amp   utf8   

原文地址:https://www.cnblogs.com/www1707/p/10692436.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!