Python爬取酷狗TOP100

匿名 (未验证) 提交于 2019-12-02 22:56:40
import time import requests from bs4 import BeautifulSoup headers={     'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36' } def get_info(url):     req=requests.get(url=url,headers=headers)     soup=BeautifulSoup(req.text,'lxml')     ranks=soup.select('.pc_temp_num')     titles=soup.select('.pc_temp_songlist > ul > li > a')     times=soup.select('.pc_temp_time')     for rank,title,time in zip(ranks,titles,times):         data={             'rank':rank.get_text().strip(),             'title':title.get_text().split('-')[1].strip(),             'signer': 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,36)]     for url in urls:         get_info(url)         time.sleep(1)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!