[Python] 1, python mouse click, mobile event Application-Write a program to automatically download Baidu music

Source: Internet
Author: User

1, Problem Description:

Recently Baidu always love to do some damage to the user's trust-----------------------

http://yinyueyun.baidu.com/

But the problem is that there is no bulk download in the cloud music, and I have saved over 700 music in total!

Therefore: it is necessary to write a script to download these music automatically!!!

2, solve the problem

There are two ways to download songs automatically:

    • JS method
    • Analog mouse click Method

Considering the JS method needs to analyze the structure of the Web page, looking for download links, the workload is a bit large, so choose to use analog mouse click Method!

On Linux, I first thought about doing this with Python.

Using Python mouse Click event is relatively simple, on github someone open source a pymouse module, a few lines of code can be simulated mouse!

Https://github.com/pepijndevos/PyMouse/wiki/Documentation

The Pymouse has a simple demo:

1 #Import the module2  fromPymouseImportPymouse3 4 #instantiate an Mouse object5m =Pymouse ()6 7 #move the mouse to int x and int y (these is absolute positions)8M.move (200, 200)9 Ten #Click Works about the same, except for int button possible values is 1:left, 2:right, 3:middle OneM.click (500, 300, 1) A  - #get the screen size - m.screen_size () the #(1024x768, 768) -  - #get the mouse position - m.position () + #(a)

Therefore, write a script that automatically downloads one page of the song (20 songs) as follows:

The main task of the code is to click Download, then click OK:

Note: If just two clicks how to interpret 21, 22 lines of code?

Because after clicking on the download, there will be a choice to download the sound quality of the box, the sound quality has high, medium and low three kinds, but some songs only one or two sound quality can be selected. This causes the position of the box to be different (to determine the position of the button), and a "dumb" way to solve the problem is to point the possible area over!

1 #Import the module2  fromPymouseImportPymouse3  fromTimeImportSleep4 5 #instantiate an Mouse object6m =Pymouse ()7 8pos_x = 11209Pos_y = 302TenPos_y_add = 38 OneOne_page_lines = 20 A  -select_button_x = 984 -select_button_y = 550 the  -Sleep (2) -  -  forIinchRange (0,one_page_lines): +M.click (pos_x,pos_y+i*38,1) -Sleep (2) +      forJinchRange (0,30): AM.click (select_button_x,select_button_y+j*5,1) atSleep (3) -     Print(i)

3. Legacy issues

The above script can be in good condition to download a page of songs to the local, the next natural thought is analog mouse drag (drag slide bar, switch to the next page 20 songs).

So I try to write a script that simulates the drag of the mouse to do a test:

1 #Import the module2  fromPymouseImportPymouse3  fromTimeImportSleep4 5 #instantiate an Mouse object6m =Pymouse ()7 8pos_x = 11209Pos_y = 302TenPos_y_add = 38 OneOne_page_lines = 20 A  -select_button_x = 984 -select_button_y = 550 the  -slide_x = 1915 -slide_y = 312 -Slide_dis = 1 +  -Sleep (5) +  forPageinchRange (1,40): A m.press (slide_x,slide_y) atslide_y = slide_y +Slide_dis - M.move (slide_x,slide_y) - m.release (slide_x,slide_y) -Sleep (10) - 

Theoretically every sliding slide bar song list moving distance is the same, and the actual measurement found there is no regular error!

Since the script for downloading songs in the second section is fixed for the start position of the mouse click, it will cause the download script to click the wrong place if the song list is not cut to the next page by slide bar move.

Subsequent optimization directions can be used to calibrate the slide bar movement using image recognition ~

:: If you feel good, please recommend to more people to help them solve the problem in the pit of real problems faster!

@beautifulzzzz Intelligent Hardware, Internet of things, love technology, focus on products blog: http://blog.beautifulzzzz.com Group of Friends: 414948975

[Python] 1, python mouse click, mobile event Application-Write a program to automatically download Baidu music

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.