11 按照提示输入歌手名字,爬取该歌手所有歌曲信息
Posted www1707
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了11 按照提示输入歌手名字,爬取该歌手所有歌曲信息相关的知识,希望对你有一定的参考价值。
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=‘ ‘) 24 print(music_list[i][‘name‘],end=‘ ‘) 25 print(music_list[i][‘album‘][‘name‘],end=‘ ‘) 26 print(music_list[i][‘interval‘],end=‘ ‘) 27 print(music_list[i][‘url‘])
以上是关于11 按照提示输入歌手名字,爬取该歌手所有歌曲信息的主要内容,如果未能解决你的问题,请参考以下文章