Recently, the guy said that his girlfriend can real-time monitor his micro blog a dynamic update, to the last scene caught are a face meng force;

So he came up to me and asked me how his girlfriend found out about his twitter updates, trying to figure out what was going on.

This has to be arranged. Let’s have a good time

See the specific operation mode below:

Related tools

Python version: 3.6.4

Related modules:

DecryptLogin module;

And some modules that come with Python.

I. Project requirements

Real-time monitoring of whether a microblog user has posted new microblog.

Two. Micro-blog simulation landing

The DecryptLogin library that I opened source before makes it very easy to simulate logging in to twitter.

Module Address:

https://github.com/CharlesPikachu/DecryptLoginCopy the code

3. Micro-blog monitoring

1. Determine the user to be monitored

(1) Specify the user ID for microblog monitoring

This is very simple, log in the mobile terminal of Weibo in the browser, and then click on the weibo home page of the user you want to monitor, you can find the user ID, as shown in the following figure:

(2) Monitor a user in the concern list

Simple packet capture can be found:

Simply request the link in the red box in the above image until the data returned is empty to obtain the information of all users in the logged-in user’s focus list, as follows:

Then the user chooses the weibo user to monitor:

After the user is selected, regular expression is used to obtain the user ID of the weibo user:

2. Realize microblog monitoring

Step 1: Obtain all microblogs published by monitored micro-blog users

Through packet capture analysis and actual test, the process of obtaining all microblogs released by monitored microblogs users is as follows:

① Obtain the first containerIDCopy the code

The session in login state requests the user’s home page and retrieves cookies from the session through regular expression.

② Obtain the second ContainerIDCopy the code

With the first containerID, user_id request:

https://m.weibo.cn/api/container /getIndex?uid={}&luicode=10000011&lfid=231093_-_ selffollowed& Type =uid&value={}& containerId ={} To obtain the second containerID.Copy the code

③ Obtain all microblog data released by monitored microblog users

Use the second containerID, user_id request:

https://m.weibo.cn/api/container/getIndex?
uid={}&luicode=10000011&lfid=231093_-_selffollowed&
type=uid&value={}&containerid={}Copy the code

It can obtain all micro-blog data published by monitored micro-blog users.

Step 2: Real-time monitoring

Step 1 is repeated repeatedly to obtain all microblogs published by monitored micro-blog users and compare the obtained data with all microblogs published by monitored micro-blog users acquired last time. If there is new data, it means that the monitored micro-blog users have released new microblogs.

The specific code is as follows:

Results show

Operation mode:

Effect demonstration:

The last

If you still can’t write this script, you can pay attention to xiaobian + forward this article, and then small private letter “monitoring”, you can get the complete code, or find my guidance to achieve positioning, the original is not easy!

Click here to learn more and learn more about the Python zero-based crawler

To learn more