I used Python to climb the popular comments of Lu Han and Guan Xiaotong micro-blog, and conducted an emotional analysis.

2018-07-19

It is believed that the recent science and technology circle has been teasing one thing: a micro-blog at noon on October 8th triggered a wave of sina micro-blog users (especially female users), causing the Sina micro-blog to be paralyzed.

I used Python to climb the popular comments of Lu Han and Guan Xiaotong micro-blog, and conducted an emotional analysis.

This article mainly involves knowledge points including Sina micro-blog crawler, simple reading and writing of Python to database, simple list data deweighting and Natural Language Processing (snowNLP module, machine learning). Suitable for a certain programming foundation, and have some understanding of Python’s potted friends reading.

The founder of this micro-blog is the global idol idol star Lu Han.

I used Python to climb the popular comments of Lu Han and Guan Xiaotong micro-blog, and conducted an emotional analysis.

The programmers began to open up the discussion.

Detailed content can be seen in yesterday’s picture and text: How did Lu Han explode the micro-blog server?

I used Python to climb the popular comments of Lu Han and Guan Xiaotong micro-blog, and conducted an emotional analysis.

How did micro-blog engineers work overtime while they were married?

I used Python to climb the popular comments of Lu Han and Guan Xiaotong micro-blog, and conducted an emotional analysis.

How do Taobao programmers forgive deer Han:

I used Python to climb the popular comments of Lu Han and Guan Xiaotong micro-blog, and conducted an emotional analysis.

At this moment, the whole world knows that Lu Han is in love.

I used Python to climb the popular comments of Lu Han and Guan Xiaotong micro-blog, and conducted an emotional analysis.

The global women’s deer have lost their love together.

So what about the sentiments of Lu Han’s fans? Let’s analyze micro-blog’s comments on Lu Han’s love affair, and analyze the mood of the fans during the analysis, and listen to me. (to see the results of the analysis can jump directly to the fifth section)

Sina micro-blog API

Having experienced several reptiles of the reptile (really painful), I learned to check the habit of API before climbing the website.

Sina, as a big factory, does not launch Sina micro-blog API, and has its own open platform for developer Sina. This is the way Python calls micro-blog API to access API code by logging in and App_secret. The code is based on PY2. There are some problems with the use of PY3 for the Weibo module.

  1. From Weibo import APIClient
  2. Import WebBrowser
  3. Import sys
  4. Reload (sys)
  5. Sys.setdefaultencoding (' utf-8')
  6. APP_KEY = ' your App Key ' the App Key acquired by H.
  7. APP_SECRET = ' your AppSecret' AppSecret obtained by Mr.
  8. CALLBACK_URL = ' https://api.weibo.com/oauth2/default.html' callback callback link
  9. Client = APIClient (app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
  10. Url = client.get_authorize_url ()
  11. Webbrowser.open_new (URL) opens the default browser to get the code parameter.
  12. Print ' enter the contents behind code in URL and press enter: '
  13. Code = raw_input ()
  14. R = client.request_access_token (code)
  15. Access_token = r.access_token
  16. Expires_in = r.expires_in
  17. Client.set_access_token (access_token, expires_in)

How do you know how to log in to API? How do you call API to climb micro-blog’s comment? A line of code is done.

R = client.comments.show.get (id = 4160547165300149, count = 200, page = 1).

All the comment information about single micro-blog is in r.comments, which needs to be compared to the micro-blog API document, and micro-blog API has a declaration that the micro-blog review API needs to be authorized by the user.

爱上海419论坛 爱上海