def get_info(url):
wb_data = requests.get(url, headers=headers)
soup = BeautifulSoup(wb_data.text, 'lxml')
ranks = soup.select('span.pc_temp_num')
titles = soup.select('div.pc_temp_songlist > ul > li > a')
times = soup.select('span.pc_temp_tips_r > span')
for rank, title, time in zip(ranks, titles, times):
data = {
'rank': rank.get_text().strip(),
'singer': title.get_text().split('-')[1].strip(),
'song': title.get_text().split('-')[0].strip(),
'time': time.get_text().strip()
}
print(data)
if __name__ == '__main__':
urls = ['http://www.kugou.com/yy/rank/home/{} - 8888.html'.format(str(i)) for i in range(1, 2)]
for url in urls:
get_info(url)
time.sleep(1)
import requests
from bs4 import BeautifulSoup
import time
import xlwt
def get_info(url):
wb_data = requests.get(url, headers=headers)
soup = BeautifulSoup(wb_data.text, 'lxml')
ranks = soup.select('span.pc_temp_num')
titles = soup.select('div.pc_temp_songlist > ul > li > a')
times = soup.select('span.pc_temp_tips_r > span')
for rank, title, time in zip(ranks, titles, times):
data = {
'排名': rank.get_text().strip(),
'歌手': title.get_text().split('-')[1].strip(),
'歌曲': title.get_text().split('-')[0].strip(),
'时间': time.get_text().strip()
}
print(data)
if __name__ == '__main__':
urls = ['http://www.kugou.com/yy/rank/home/{} - 8888.html'.format(str(i)) for i in range(1, 2)]
for url in urls:
get_info(url)
time.sleep(1)