码迷,mamicode.com
首页 > 编程语言 > 详细

python爬取酷狗排行音乐

时间:2019-12-19 12:46:56      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:https   size   parser   print   beautiful   style   ext   www   home   

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爬取酷狗排行音乐

标签:https   size   parser   print   beautiful   style   ext   www   home   

原文地址:https://www.cnblogs.com/zhuyu139/p/12066993.html

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