本文主要是介绍python网络爬虫-爬取酷狗TOP500的数据 源码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一家懂得用细节留住客户的3年潮牌老店我必须支持!➕🛰:luyao1931
python网络爬虫-爬取酷狗TOP500的数据
import requests
from bs4 import BeautifulSoup
import timeheaders = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
}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('-')[0],'song':title.get_text().split('-')[0],'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,24)]for url in urls:get_info(url)time.sleep(1)
这篇关于python网络爬虫-爬取酷狗TOP500的数据 源码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!