python爬取酷狗排行音乐

Posted zhuyu123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python爬取酷狗排行音乐相关的知识,希望对你有一定的参考价值。

import time
import requests
from bs4 import BeautifulSoup
urlFormat=https://www.kugou.com/yy/rank/home/{}-8888.html
count=1
rank=1
while 1:
    url=urlFormat.format(count)
    res=requests.get(url)
    soup=BeautifulSoup(res.text, html.parser)
    songName=[s.text.strip() for s in soup.select(a.pc_temp_songname)]
    songTime=[s.text.strip() for s in soup.select(span.pc_temp_time)]
    if songName and songTime:
        for sName,sTime in zip(songName,songTime):
            print({: <4}{}{}.format(rank,sName,sTime))
            rank+=1
        count+=1
        time.sleep(1)
    else:
        break

以上是关于python爬取酷狗排行音乐的主要内容,如果未能解决你的问题,请参考以下文章

python使用beautifulsoup4爬取酷狗音乐

爬取酷狗音乐Top500

Python爬虫爬取酷狗音乐网络红歌榜

爬取酷狗音乐Top500榜单

爬取酷狗音乐华语新歌榜前100

爬虫程序2-爬取酷狗top500