-*- coding: utf-8 -*-
"""
Created on Tue Oct 27 19:25:44 2020
@author: lenovo
"""
import requests
from bs4 import BeautifulSoup
import time
headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3823.400 QQBrowser/10.6.4302.400'
}
def get_info(url):
wb_data = requests.get(url,headers = headers)
soup = BeautifulSoup(wb_data.text,'lxml')
ranks = soup.select('#rankWrap > div.pc_temp_songlist > ul > li:nth-child(1) > span.pc_temp_num > strong')
tittles = soup.select('#rankWrap > div.pc_temp_songlist > ul > li:nth-child(1) > a')
times = soup.select('#rankWrap > div.pc_temp_songlist > ul > li:nth-child(1) > span.pc_temp_tips_r > span')
for rank,tittle,time in zip(ranks,tittles,times):
data = {
'rank':rank.get_text().strip(),
'singer':tittle.get_text().split('-')[0],
'song':tittle.get_text().split('-')[1],
'time':time.get_text().strip()
}
print(data)
if name == '__main__':
urls = ['https://www.kugou.com/yy/rank/home/{}-8888.html'.format(str(i)) for i in range (1,24)]
for url in urls:
get_info(url)
time.sleep(1)
