網易雲熱歌榜歌名與熱評的高頻詞抓取及詞云製作

2021-10-25 09:17:29 字數 4686 閱讀 1111

#!/usr/bin/env python3

import re

import urllib.request

import urllib.error

import urllib.parse

』 #進行第一次篩選的正規表示式

result=re.compile(pat1).findall(html) #用正規表示式進行篩選

result=result[0] #獲取tuple的第乙個元素

pat2=r'(.*?)

' #進行歌名篩選的正規表示式

hot_song_name=re.compile(pat2).findall(result) #獲取所有熱門歌曲名稱

return hot_song_name

def get_name(hot_song_name):

fhandle=open(』./song_name.txt』,『a』,encoding=『utf-8』) #寫入檔案

fhandle.write(hot_song_name+』\n』)

fhandle.close()

hot_song_name=get_all_hotsong() #獲取熱歌榜所有歌曲名稱

num=0

while num < 192: #儲存所有熱門歌名

print(『正在抓取第%d首歌…』%(num+1))

get_name(hot_song_name[num])

print(『第%d首歌名抓取成功』%(num+1))

num+=1

#製作網易雲熱歌榜歌名詞雲

』 #進行第一次篩選的正規表示式

result=re.compile(pat1).findall(html) #用正規表示式進行篩選

result=result[0] #獲取tuple的第乙個元素

pat2=r'(.*?)

' #進行歌名篩選的正規表示式

pat3=r'.*?

' #進行歌id篩選的正規表示式

hot_song_name=re.compile(pat2).findall(result) #獲取所有熱門歌曲名稱

hot_song_id=re.compile(pat3).findall(result) #獲取所有熱門歌曲對應的id

return hot_song_name,hot_song_id

num=0

fhandle=open('./song_comments.txt','a',encoding='utf-8') #寫入檔案

fhandle.write(hot_song_name+':'+'\n')

for item in hot_comment:

num+=1

fhandle.write(str(num)+'.'+item['content']+'\n')

fhandle.write('\n*********************************************=\n\n')

fhandle.close()

hot_song_name,hot_song_id=get_all_hotsong() #獲取熱歌榜所有歌曲名稱和id

num=0

while num < len(hot_song_name): #儲存所有熱歌榜中的熱評

print(『正在抓取第%d首歌曲熱評…』%(num+1))

get_hotcomments(hot_song_name[num],hot_song_id[num])

print(『第%d首歌曲熱評抓取成功』%(num+1))

num+=1

#製作網易雲熱歌榜熱評詞云

Python 詞云 《長恨歌》

結果展示 text原文 import matplotlib.pyplot as mp,jieba,requests,re from wordcloud import wordcloud 讀取文字 url header r requests.get url,headers header text re...

普歌 雲言團隊 Request物件簡析

request定義 request物件是servlet中service的乙個引數,當瀏覽器發出請求時,伺服器會自動建立乙個reques物件,用來封裝請求資料,然後在servlet中呼叫service方法時,將request物件依次傳遞到各個servlet,請求資料進行處理。request的使用 1,...

Jsrpc學習 網易雲熱評加密函式逆向

前幾天給大家分享jsrpc的介紹篇,python網路爬蟲之js逆向之遠端呼叫 rpc 免去摳 補環境簡介,感興趣的小夥伴可以戳此文前往。今天給大家來個jsrpc實戰教程,jsrpc學習 cookie變化的 破解教程,讓大家繼續加深對jsrpc的理解和認識。下面是具體操作過程,不懂的小夥伴可以私我。1...