The foreword / 1 /

Hey, everyone good evening, today xiaobian again to you dry goods content, today brought is how to automatically log in the drawer, and like!

The original plan was not to use Selenium, but because it involves liking, it is unavoidable to log in. But as it turns out, I was slapped in the face, the drawer login is really difficult, various parameters put me dry meng. After all, I picked up Selenium. It’s hard to escape the principle of Selenium.

All right, let’s cut to the chase!

/2 Preparation /

The same suit…

Chrome Driver: a browser driver that can be interpreted as a Chrome browser without an interface.

Selenium is used to simulate human click, output, drag and drop operations on a browser, which is similar to using a browser by an individual, and is often used to deal with anti-crawler measures.

/3 Drawer thumbs-up mechanism /

As we all know, in order to like, we need to know who clicked the “like” button. After logging in, we need to save the state, generally there are cookie, seeeion, token three forms, so how to play the drawer? Let’s draw a picture, as shown below.

From the above figure, we can see at a glance that once we log in and get the cookie, we will not use Selenium in the future. Therefore, we will log in to get cookies and like separate, separate, logic is very clear, and do not delay things.

/4 Login preheat /

Drawer url:dig.chouti.com/, straight here.

A hot list of information community, roughly like this, as shown below, the content is quite good.


In the figure above, we can see the login button in the upper right, and the icon to like, the number of likes, comments and favorites can be seen on the left. Next, we will perform the first step of automatic login.

/5 Start login /

Click the login button in the upper right, and the page will jump to a login interface, as shown in the picture below.


The login mode dialog box pops up. Next, we use Selenium to start it, directly to the code, as shown below.

Note 1: For reasons of length and layout, this is only a code screenshot. I left the Github link for the complete code at the end of the article, and you can directly go down later.

Because this login is a modal dialog, you cannot click the login button with Selenium and need to execute the JS code, as shown in the figure below.


How does Cookie play? I wrote it locally, but testing found selenium does not get cookies completely, so we still use JS to get cookies.


Note 2: If the drawer is logged in too much, it may cause input of slider verification code and so on, which is not dealt with in this part of this article.

/6 Automatic login example /

The effect of automatic login is shown below:


/7 Start automatic thumbs-up /

In the above work, we have successfully obtained the cookies returned by login, and then we will start to automatically like, and with the previous foundation, the following things are much easier to do.

We first need to look at which interface the like request is being made. Let’s clear the NetWork log in our browser and click the “like” button for the first post, as shown below.

As you can see, this interface is sending a POST request, but what data is it sending? Let’s go down and find out more.


You can see that in the Form Data, there is linkid: 29213534, which is a long number. What is this? Find out soon!

Using the browser-web interface, we click on the corresponding article, and soon we can lock the Linkid, as shown below.


I’m sure you can see that the string of numbers in the post is actually the article ID. In other words, we just need to get this ID, put it in the POST construction data, run the application, and then we can achieve the like!

/8 code implementation /

The following is part of the code screenshot, the complete code at the end of the article, as shown below.

Note: Only the first 10 articles were tested here.

/9 drawer automatic thumbs-up renderings /

In order to facilitate you to view, I made a simple small dynamic diagram for you, the details are as follows.



If the GIF is not very clear, don’t panic, xiaobian has put the original image on Github, you can visit to have a look, very clear, as shown below. Github link at the end of the article, welcome everyone to poke!


/10 drawer automatic thumbs-up renderings /

The code details I have uploaded to github here: github.com/cassieeric/… . If you feel good, remember to give a star oh, feel the support of friends