It should have been last year. Brush Zhihu saw a question about how to brush the accumulated number of songs that Netease cloud music individuals listened to. Then he had a highly praised answer, posted a section of JS code, and executed it directly in the browser console. At that time, I tried it and directly brushed it for tens of thousands. Tragically, the next day it returned to its original form, which was apparently blocked by the discovery of Netease cloud music. In addition, Netease cloud added some restrictions on the cumulative number of songs it listened to, with a maximum of 300 songs per day. Today, it brings a way of automatically playing songs through java + selenium to achieve the effect of brushing the cumulative number of songs. In addition, with the help of this demo, I am more familiar with the use of selenium, which is also some interesting things in the crawler application.
There are two ways to log in:
A. simulate the login process of the web. Advantage: this method is more general and convenient for dynamic account switching. Disadvantages: it’s a little bit more troublesome than using cookies directly, and there is a certain chance that a graphic verification code will appear, which needs to be considered.
B. set cookies. Advantages: no need to deal with the login process, which is relatively simple and convenient. It is more convenient when the cookie expires for a long time, and no need to switch frequently. Disadvantages: it’s troublesome to switch accounts, unable to achieve automation. I choose this method here.
Play: after successful login in the previous step, directly open the song list page. Following chart
, you can see it on the song list page. There are three places where you can click to play. The first thing I think of is the bottom play button. Then I keep the display of the bottom play component and get the real-time play dynamic. Try to click the play button through simulation, which is always unsuccessful. Finally, click the top play button to play.
Get play dynamic: in order to determine whether the play is in normal progress, you can get the accumulated songs related information of the personal home page in real time for monitoring. Since there is already a page playing songs, in order not to affect the original page playing songs, you can open a new tab page to get the personal home page and open a new table page. Here, JS is used
In the end, you will see the following format logs, which indicates success:
2019-03-26 09:25:10406 info [, main] - [com. GitHub. Wycm. Music163] - Yili Riverside - 00:00 / 00:00 --- the first song is currently played, and the total listening time is 20572 2019-03-26 09:25:16817 info [, main] - [com. GitHub. Wycm. Music163] - Yili Riverside - 01:00 / 07:19 --- currently playing the first song, listening to the song accumulatively: 20572 2019-03-26 09:25:23157 info [, main] - [com. GitHub. Wycm. Music163] - Yili Riverside - 01:06 / 07:19 --- currently playing the first song, listening to the song accumulatively: 20572 2019-03-26 09:25:29394 info [, main] - [com. GitHub. Wycm. Music163] - Yili Riverside - 01:13 / 07:19 --- currently playing the first song, listening to the song accumulatively: 20572 2019-03-26 09:25:35592 info [, main] - [com. GitHub. Wycm. Music163] - Yili Riverside - 01:19 / 07:19 --- currently playing the first song, listening to the song accumulatively: 20572 2019-03-26 09:25:41974 info [, main] - [com. GitHub. Wycm. Music163] - Yili Riverside - 01:25 / 07:19 --- currently playing the first song, listening to the song accumulatively: 20572
- Modify the path configuration of your own related chrome driver
- Log in to your own web-based Netease cloud music: https://music.163.com/
- Copy the original cookies successfully logged in by yourself to the raw ﹣ cookies field in the code
- Switch the song list. If the default song list is played, you can search for some songs that have not been played, similar to
https://music.163.com/#/playlist?id=22336453To extract the ID and directly replace the startid field in the code.
- You may have questions. I want to put this task on my own server and run it directly in the background. This is the problem of setting up selenium running environment on the server. Please refer to my previous article. Alibaba cloud and Tencent cloud have the lowest matching servers that can run.
- In addition, why is selenium adopted here? Is there any other simpler way to achieve the effect of brushing directly through simple HTTP request. I have personally tried to find the request to increase the number of songs I listen to in the way of pure HTTP request. Because the requests of online banking cloud are encrypted, they are not found at last. So we use selenium instead.
See https://github.com/wycm/crawler-set/tree/master/music163 for the complete project code
The above is the whole content of this article. I hope it will help you in your study, and I hope you can support developepaer more.