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.
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.
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?
How did micro-blog engineers work overtime while they were married?
How do Taobao programmers forgive deer Han:
At this moment, the whole world knows that Lu Han is in love.
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.
- From Weibo import APIClient
- Import WebBrowser
- Import sys
- Reload (sys)
- Sys.setdefaultencoding (' utf-8')
- APP_KEY = ' your App Key ' the App Key acquired by H.
- APP_SECRET = ' your AppSecret' AppSecret obtained by Mr.
- CALLBACK_URL = ' https://api.weibo.com/oauth2/default.html' callback callback link
- Client = APIClient (app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
- Url = client.get_authorize_url ()
- Webbrowser.open_new (URL) opens the default browser to get the code parameter.
- Print ' enter the contents behind code in URL and press enter: '
- Code = raw_input ()
- R = client.request_access_token (code)
- Access_token = r.access_token
- Expires_in = r.expires_in
- 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.