《獵罪圖鑒》可以說是國產懸疑劇之光了,上線首周熱度不斷飆升,
該劇講述了因一起塵封舊案而結怨的模擬畫像師沈翊和刑警隊長杜城,在機緣巧合下被迫搭檔,兩人聯手偵破多起離奇疑案,共同追蹤謎底真相的故事,
今天就用Python爬取該劇彈幕,做詞云圖
環境介紹
python 3.8
pycharm
requests >>> pip install requests
pyecharts >>> pip install pyecharts
對于本篇文章有疑問的同學可以加【資料白嫖、解答交流群:910981974】
視頻彈幕收集
請求資料
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36'
}
for page in range(15, 1500, 30):
url = f'https://mfm.XXXX.com/danmu?otype=json&target_id=7712618480%26vid%3Dg00423lkmas&session_key=0%2C0%2C0×tamp={page}&_=1647931110703'
response = requests.get(url=url, headers=headers)
獲取資料 從一個字串 變成了一個 字典 (容器)
json_data = response.json()
決議資料
for comment in json_data['comments']:
commentid = comment['commentid']
opername = comment['opername']
content = comment['content']
保存資料
with open('彈幕.csv', encoding='utf-8-sig', mode='a', newline='') as f:
csv_writer = csv.writer(f)
csv_writer.writerow([commentid, opername, content])
運行代碼,得到1W多條彈幕資料

詞云可視化
匯入資料
wordlist = []
data = pd.read_csv('彈幕.csv')['content']
data
詞云圖
a = [list(z) for z in zip(word, count)]
c = (
WordCloud()
.add('', a, word_size_range=[10, 50], shape='circle')
.set_global_opts(title_opts=opts.TitleOpts(title="詞云圖"))
)
c.render_notebook()

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/451997.html
標籤:其他
上一篇:10行代碼實作一個值班提醒應用
下一篇:集合(模擬斗地主發牌)
