欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python爬取酷狗音樂Top500榜單

 更新時(shí)間:2022年02月07日 08:58:52   作者:Ding?Jiaxiong  
大家好,本篇文章主要講的是python爬取酷狗音樂Top500榜單,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下

網(wǎng)頁情況

爬取數(shù)據(jù)包含

歌曲排名、歌手、歌曲名、歌曲時(shí)長(zhǎng)

python 代碼

import requests #請(qǐng)求網(wǎng)頁獲取網(wǎng)頁數(shù)據(jù)
  from bs4 import BeautifulSoup #解析網(wǎng)頁數(shù)據(jù)
  import time #時(shí)間庫
  #user-Agent,偽裝成瀏覽器,便于爬蟲的穩(wěn)定性
  headers = {
      "User-Agent":
      "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
  }
  def get_info(url):
      web_data = requests.get(url,headers= headers)
      soup = BeautifulSoup(web_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().replace("\n","").replace("\t","").split('-')[1],
              "song":title.get_text().replace("\n","").replace("\t","").split('-')[0],
              "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)

運(yùn)行效果

總結(jié)

到此這篇關(guān)于python爬取酷狗音樂Top500榜單的文章就介紹到這了,更多相關(guān)python爬取酷狗音樂榜單內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論