In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use python to grab small broken station data". In the daily operation, I believe that many people have doubts about how to use python to grab small broken station data. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to grab small broken station data with python"! Next, please follow the editor to study!
Overview
Available data include:
Video- video module
User- user module
Dynamic- dynamic module
This time, use the video of the 10th anniversary special of "Running Man" to make a Demo to capture the on-screen comment.
I'm a comparison.
If there is no comparison, there will be no harm, just like a recent student of Harbin University of Technology and a student of Zhejiang University.
This is the process of getting the on-screen comment before:
1. On-screen comment data interface
Https://comment.bilibili.com/123072475.xml (a fixed url address + cid + .xml for video)
2. Use Request module to obtain data.
3. Use Xpath to parse data
Next, it's time to perform real technology.
After being encapsulated by bilibili_api, the data acquisition part of the on-screen comment only uses one line of code:
Danmu = video_info.get_danmaku ()
Accordingly, it is equally convenient to get the basic information and comment information of the video.
Basic_info = video_info.get_video_info () comments = video_info.get_comments () Quick start
Next, this article will use bilibili_api to obtain the data of the 10th anniversary special of "Running Man" and draw the word cloud.
Bilibili has an av number and a bv number. After the revision, the bv number is directly displayed in the link. One of these two must be provided.
Bvid is the unique identifier of bilibili's new video. It consists of 12 digits and letters. It is case sensitive. Please include the "BV" in the header when you enter it.
For example: "BV1gC4y1h722"
1) installation process
Installation depends on the request module, which encapsulates the API of bilibili data.
You can install it through pip:
Pip install bilibili_api
Import module
From bilibili_api import Verifyfrom bilibili_api.video import VideoInfofrom bilibili_api.video import Danmaku
VideoInfo-get video information (on-screen comment, coin count, playback, etc.)
Danmaku class-on-screen comment class, used to obtain and send on-screen comments
Verify class, available or not. Some of the video information needs to be logged in (that is, SESSDATA is required) before it can be used (such as obtaining historical on-screen comments).
SESSDATA and csrf are required for user operations such as likes and coins for videos.
2) obtain on-screen comment data
Create a VideoInfo object, passing in two parameters:
Bvid= "BV1gC4y1h722" (BV number of the video)
Verify=verify (get the on-screen comment based on sessdata and csrf)
The obtained on-screen comment data is a list of "Danmaku class". By traversing, print its text.
Post a code:
Verify= Verify (sessdata= "your", csrf= "your") video_info = VideoInfo (bvid= "BV1gC4y1h722", verify=verify) danmu = video_info.get_danmaku () for i in danmu: print (i.text) 3) draw word cloud
Draw word clouds through jieba word segmentation and WorldCloud.
You can pass in parameters such as "background color", "background image", "font" and so on through the WordCloud object.
Post a code:
Wc = WordCloud (background_color='white', mask=background_Image, font_path=r'./SourceHanSerifCN-Medium.otf', color_func=random_color_func, random_state=50,) word_cloud = wc.generate (words_str) # generate word cloud word_cloud.to_file ("rm.jpg") # Save picture # display word cloud picture plt.imshow (word_cloud) plt.axis ('off') plt.show () so far The study on "how to grab the data of small broken stations with python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.