Selenium + java crack extreme sliding verification code example code
abstract
The principle of picture confusion of verification code material is analyzed, and selenium is used to simulate the process of human dragging the slider, so as to crack the verification code.
Manual verification process
1. Open the registration page of weifeng.com
2. Move the mouse to the small slider, and a complete picture will appear (as shown in Figure 1 below)
3. Click the left mouse button and a missing block will appear in the middle of the picture (as shown in Figure 2 below)
4. Move the pattern directly above the small slider to the missing block
5. Verification passed
Selenium simulation verification process
1. When you open the Chrome browser console, you will find that the verification code image shown in Figure 1 is not the original image returned by the background of extreme test. Instead, it is composed of multiple div splices (as shown in Figure 3 below)
According to the style attribute of div displayed in the picture, the polar background cuts and misplaces the picture. Cut the material pictures into 52 small pictures with the size of 10 * 58, and then conduct dislocation processing. When displayed on the web page, restore the image through the background position attribute of CSS. The above figures 1 and 2 have undergone this process. In this case, when using selenium to simulate verification, you need to restore the downloaded verification code image. See the first div.gt in Figure 3 above_ cut_ fullbg_ Slice tag, its size is 10px * 58px, where the style attribute is background image: URL(“ http://static.geetest.com/pictures/gt/969ffa43c/969ffa43c.webp "); background position: - 157px - 58px; the image corresponding to the URL of the attribute will be translated. With the upper left corner as the reference, 157px will be translated to the left and 58px will be translated upward, and the excess part of the image will not be displayed. Therefore, the image shown in Figure 1 above is composed of 26 * 2 div with the size of 10px * 58px (as shown in Figure 4 below). The size of each small square is 58 * 10
2. Download the picture and restore it. In the previous step, the specific confusion logic of the picture is analyzed. The specific code of restoring the picture is as follows. The main logic is to cut the original picture into 52 small pictures, and then splice them into a complete picture.
During the restore process, it should be noted that the misplaced picture returned by the background is 312 * 116 in size. The size of the image div on the web page is 260 * 116.
3. Calculate the translation distance and traverse each pixel of the picture. When the sum of the differences between R, G and B of the two pictures is greater than 255, it indicates that the difference of the point is too large. It is likely that it is the point that needs to be translated to the position. The code is as follows.
4. This step is the most critical step to simulate the mouse movement event. The background of the polar verification code judges whether it is done by the machine by moving the track of the slider. The more random the whole moving track, the better. I provide a moving algorithm with high success rate. The code is as follows.
The complete code is as follows
POM file dependencies are as follows
last
The complete code has been uploaded to GitHub at: https://github.com/wycm/selenium-geetest-crack