[Python] 1, python mouse clicks, mobile event application - write a program to automatically download Baidu music

 

1. Description of the problem:

Recently Baidu love to do some damage user confidence thing - gold coins change coupons library, network disk speed, scared I quickly find a way to exist Baidu cloud music songs downloaded to the local.

http://yinyueyun.baidu.com/

The problem is not a cloud in the batch download music, and I always coexisted top 700 music!

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

 

2, to solve the problem

Automatic download songs in two ways:

  • JS method
  • Simulate mouse clicks law

Taking into account the need to analyze the page structure JS method, find the download link, the workload is a little big, so he chose to simulate a mouse click with the law!

My first thought on linux using python to do it.

Use the mouse to click events with python is relatively simple, open source on github was a PyMouse module, a few simple lines of code will be able to simulate a mouse!

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

The PyMouse there is a simple DEMO:

Copy the code
 1 # import the module
 2 from pymouse import PyMouse  3  4 # instantiate an mouse object  5 m = PyMouse()  6  7 # move the mouse to int x and int y (these are absolute positions)  8 m.move(200, 200)  9 10 # click works about the same, except for int button possible values are 1: left, 2: right, 3: middle 11 m.click(500, 300, 1) 12 13 # get the screen size 14 m.screen_size() 15 # (1024, 768) 16 17 # get the mouse position 18 m.position() 19 # (500, 300)
Copy the code

Therefore, the preparation of a can automatically download a song (20) of the script is as follows:

The main task of this code does is click to download, and then click OK:

Note: If only two clicks how to interpret the 21 lines of code?

Because after clicking download, download sound quality will have a choice of playing box, high quality, medium, and low, but some songs sound quality can be only one or two choices. This has led to bomb the frame position (to determine the position of the button also will be different), to solve this problem a "stupid" approach is likely to have areas of different point again!

Copy the code
 1 # import the module
 2 from pymouse import PyMouse  3 from time import sleep  4  5 # instantiate an mouse object  6 m = PyMouse()  7  8 pos_x = 1120  9 pos_y = 302 10 pos_y_add = 38 11 one_page_lines = 20 12 13 select_button_x = 984 14 select_button_y = 550 15 16 sleep(2) 17 18 for i in range(0,one_page_lines): 19 m.click(pos_x,pos_y+i*38,1) 20 sleep(2) 21 for j in range(0,30): 22 m.click(select_button_x,select_button_y+j*5,1) 23 sleep(3) 24 print(i)
Copy the code

 

3, the remaining issues

The above script can be a song downloaded to the local speed in good condition, then naturally think of it is to simulate a mouse drag (drag the slide bar, switch to the next 20 songs).

So I try to write a script to simulate a mouse drag to be a test:

Copy the code
 1 # import the module
 2 from pymouse import PyMouse  3 from time import sleep  4  5 # instantiate an mouse object  6 m = PyMouse()  7  8 pos_x = 1120  9 pos_y = 302 10 pos_y_add = 38 11 one_page_lines = 20 12 13 select_button_x = 984 14 select_button_y = 550 15 16 slide_x = 1915 17 slide_y = 312 18 slide_dis = 1 19 20 sleep(5) 21 for page in range(1,40): 22  m.press(slide_x,slide_y) 23 slide_y = slide_y + slide_dis 24  m.move(slide_x,slide_y) 25  m.release(slide_x,slide_y) 26 sleep(10) 27 
Copy the code

Theoretically, the slide movement distance slide bar song list is the same, an error is found and measured in the absence of the law!

Since the second section of the script to download songs click on the start position is fixed, and therefore can not be used once the slide bar to move the list of songs just cut to the next page, click on the event will lead to the download scripts point to the wrong place.

Subsequent optimization may utilize image recognition direction slide bar moving calibration ~

 

https://www.cnblogs.com/zjutlitao/p/6942729.html

1. Description of the problem:

Recently Baidu love to do some damage user confidence thing - gold coins change coupons library, network disk speed, scared I quickly find a way to exist Baidu cloud music songs downloaded to the local.

http://yinyueyun.baidu.com/

The problem is not a cloud in the batch download music, and I always coexisted top 700 music!

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

 

2, to solve the problem

Automatic download songs in two ways:

  • JS method
  • Simulate mouse clicks law

Taking into account the need to analyze the page structure JS method, find the download link, the workload is a little big, so he chose to simulate a mouse click with the law!

My first thought on linux using python to do it.

Use the mouse to click events with python is relatively simple, open source on github was a PyMouse module, a few simple lines of code will be able to simulate a mouse!

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

The PyMouse there is a simple DEMO:

Copy the code
 1 # import the module
 2 from pymouse import PyMouse  3  4 # instantiate an mouse object  5 m = PyMouse()  6  7 # move the mouse to int x and int y (these are absolute positions)  8 m.move(200, 200)  9 10 # click works about the same, except for int button possible values are 1: left, 2: right, 3: middle 11 m.click(500, 300, 1) 12 13 # get the screen size 14 m.screen_size() 15 # (1024, 768) 16 17 # get the mouse position 18 m.position() 19 # (500, 300)
Copy the code

Therefore, the preparation of a can automatically download a song (20) of the script is as follows:

The main task of this code does is click to download, and then click OK:

Note: If only two clicks how to interpret the 21 lines of code?

Because after clicking download, download sound quality will have a choice of playing box, high quality, medium, and low, but some songs sound quality can be only one or two choices. This has led to bomb the frame position (to determine the position of the button also will be different), to solve this problem a "stupid" approach is likely to have areas of different point again!

Copy the code
 1 # import the module
 2 from pymouse import PyMouse  3 from time import sleep  4  5 # instantiate an mouse object  6 m = PyMouse()  7  8 pos_x = 1120  9 pos_y = 302 10 pos_y_add = 38 11 one_page_lines = 20 12 13 select_button_x = 984 14 select_button_y = 550 15 16 sleep(2) 17 18 for i in range(0,one_page_lines): 19 m.click(pos_x,pos_y+i*38,1) 20 sleep(2) 21 for j in range(0,30): 22 m.click(select_button_x,select_button_y+j*5,1) 23 sleep(3) 24 print(i)
Copy the code

 

3, the remaining issues

The above script can be a song downloaded to the local speed in good condition, then naturally think of it is to simulate a mouse drag (drag the slide bar, switch to the next 20 songs).

So I try to write a script to simulate a mouse drag to be a test:

Copy the code
 1 # import the module
 2 from pymouse import PyMouse  3 from time import sleep  4  5 # instantiate an mouse object  6 m = PyMouse()  7  8 pos_x = 1120  9 pos_y = 302 10 pos_y_add = 38 11 one_page_lines = 20 12 13 select_button_x = 984 14 select_button_y = 550 15 16 slide_x = 1915 17 slide_y = 312 18 slide_dis = 1 19 20 sleep(5) 21 for page in range(1,40): 22  m.press(slide_x,slide_y) 23 slide_y = slide_y + slide_dis 24  m.move(slide_x,slide_y) 25  m.release(slide_x,slide_y) 26 sleep(10) 27 
Copy the code

Theoretically, the slide movement distance slide bar song list is the same, an error is found and measured in the absence of the law!

Since the second section of the script to download songs click on the start position is fixed, and therefore can not be used once the slide bar to move the list of songs just cut to the next page, click on the event will lead to the download scripts point to the wrong place.

Subsequent optimization may utilize image recognition direction slide bar moving calibration ~

 

https://www.cnblogs.com/zjutlitao/p/6942729.html

Guess you like

Origin www.cnblogs.com/wilson403/p/11141707.html