Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Python to collect the barrage of the sword line in the snow to make a word cloud

Shulou Source: shulou.com Published: 2022-06-02 01:11:35 10月03日 Update

This article mainly shows you "how to use Python to collect the bullet screen in the snow to make word cloud", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Python to collect the bullet screen in the snow to make word cloud" this article.

Preface

Recently, the first season of the TV series "the knife in the Snow" has been broadcast, and the audience's expectations for the show can be seen from the number of broadcasts. The total number of broadcasts has reached 5 billion, but unfortunately, Douban's score is only 5.7. it doesn't even break 6.

Many people will compare this play with "Qingyu year" because the creator has the same crew.

A novel of the same name with more than 4 million words has been hailed as a "masterpiece" in the online literary world, and many fans have long been looking forward to cross-border adaptation, which has been magnified by the same creator and producer of the play as the hit drama "Qingyu years" in 2019. However, after the broadcast of "the knife in the Snow", the anger of book fans spread to all kinds of discussion occasions.

Today, let's collect some of the video barrage of the show to see what the audience said and why the number of broadcasts is high, but word of mouth is low.

Introduction of knowledge points

The use of requests module

Pandas saves tabular data

Visualization of word Cloud Picture by pyecharts

Environment introduction

Python 3.8

Pycharm

Requests > > pip install requests

Pyecharts > > pip install pyecharts

Code implementation 1. The import module import reimport requests # sends a network request import pandas as pd # to save data 2. Send a network request 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'} # build a list to store data data_list = [] for page in range (15, 1500, 30): url= f 'https://mfm.video.qq.com/danmu?otype=json&target_id=7626435152%26vid%3Dp0041oidttf&session_key=0%2C174%2C1642248894×tamp={page}' esponse = requests.get (url=url, headers=headers) 3. Get data on-screen comment content json_data = response.json ()

Tell us that the response was successful

4. Parse data (filter data) extract something you want to ignore comments = json_data ['comments'] print (comments) for comment in comments: data_dict = {} data_dict [' commentid'] = comment ['commentid'] content = comment [' content'] content = re.sub (r'[\ X0e\ xa0]','' Content) data_dict ['content'] = content data_dict [' opername'] = comment ['opername'] print (data_dict) data_list.append (data_dict) 5. Save data df = pd.DataFrame (data_list) # garbled, and specify either utf-8 or gbk or utf-8-sigdf.to_csv ('data.csv', encoding='utf-8-sig')

6. Visualization of cloud image import jiebafrom pyecharts.charts import WordCloudimport pandas as pdfrom pyecharts import options as optswordlist = [] data = pd.read_csv ('data.csv') [' content'] dataa = [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= "word cloud map") c.render_notebook ()

The above is all the contents of the article "how to use Python to collect the bullet screen of the fierce knife line in the snow to make a word cloud". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Data content cloud map article same remaining years module team knowledge network audience creator visualization learning help success regret random code code preface Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS Shulou Tech Info Huawei Shulou Technology