python爬取酷狗音樂Top500榜單
網(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)文章
python網(wǎng)絡(luò)編程學(xué)習(xí)筆記(五):socket的一些補(bǔ)充
前面已經(jīng)為大家介紹了python socket的一些相關(guān)知識(shí),這里為大家補(bǔ)充下,方便需要的朋友2014-06-06Python模型聚合查詢\Q查詢\F查詢\分組查詢操作技巧解析
這篇文章主要介紹了模型查詢中的一些操作技巧,主要包括模型聚合查詢,Q查詢,F(xiàn)查詢,分組查詢,有需要的朋友可以借鑒參考下,希望可以有所幫助2021-09-09Pytorch中的modle.train,model.eval,with torch.no_grad解讀
這篇文章主要介紹了Pytorch中的modle.train,model.eval,with torch.no_grad解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12python 在指定范圍內(nèi)隨機(jī)生成不重復(fù)的n個(gè)數(shù)實(shí)例
今天小編就為大家分享一篇python 在指定范圍內(nèi)隨機(jī)生成不重復(fù)的n個(gè)數(shù)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-01-01