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
原文地址:https://www.cnblogs.com/zhuyu139/p/12066993.html
时间: 2024-10-08 12:27:54