百木园-与人分享,
就是让自己快乐。

为了删除数万封邮件,使用python模拟鼠标自动点击删除

公司的企业邮箱有段时间不知道为啥没有删除服务器上的邮件,屯了几万封。登陆企业邮网站,又不好清空邮箱,只能每次一页删除100封,光靠鼠标在那里点,真的费时费力。于是写了个python脚本来自动点击删除邮件。

改了几版,最终改成可以无限选择点击的位置和数量。加上设置循环次数和每轮的间隔时间,就可以使用很多场景了。不光是删除邮箱这件事。

第一版,只用于我删除21cn邮箱的步骤如下:

 1 from pymouse import PyMouse
 2 import time
 3 
 4 times = int(input(\"输入删除次数:\"))
 5 
 6 m = PyMouse()
 7 
 8 print(\"鼠标移动到\\\"全选\\\"框\")
 9 time.sleep(5)
10 selectPoint = m.position()
11 print(\"全选 坐标\",selectPoint)
12 
13 print(\"鼠标移动到\\\"彻底删除\\\"按钮\")
14 time.sleep(5)
15 deletePoint = m.position()
16 print(\"彻底删除 坐标\",deletePoint)
17 
18 print(\"鼠标移动到删除提示的\\\"确定\\\"按钮\")
19 time.sleep(5)
20 confirmPoint = m.position()
21 print(\"确定按钮坐标\",confirmPoint)
22 
23 while(times>0):
24     m.click(selectPoint[0],selectPoint[1], button=1, n=1)
25     time.sleep(1)
26     m.click(deletePoint[0],deletePoint[1], button=1, n=1)
27     time.sleep(1)
28     m.click(confirmPoint[0],confirmPoint[1], button=1, n=1)
29     times -=1
30     print(\"Deleting...%d\",times)
31     time.sleep(7)

 

第二版,改成尽量适用于点击的多种场景。可以在页面记录多次点击,如果本次和上一次重复位置,就表示结束选择点。

 

 1 from pymouse import PyMouse
 2 import time
 3 
 4 times = int(input(\"输入循环次数:\"))
 5 timeWaitNextRun = int(input(\"每轮间隔时间(秒):\"))
 6 
 7 mousePointArray = []
 8 mousePointNum = 0
 9 m = PyMouse()
10 
11 def countDown(sec):
12     while(sec>0):
13         print(\"倒计时:%d秒\"%sec)
14         time.sleep(1)
15         sec-=1
16     print(\"倒计时:%d秒\"%sec)
17 
18 def getMousePoint(m):
19     mousePoint = m.position()
20     print(\"已选定当前点\",mousePoint)
21     return mousePoint
22 
23 def checkEndingPoint(last,current):
24     print(\"last\",last,\"current\",current)
25     if(last[0] != current[0]):
26         return True
27     if(last[1] != current[1]):
28         return True
29     return False
30 
31 print(\"鼠标移动到第%d个点击点\"%(mousePointNum+1))
32 countDown(5)
33 mousePointArray.append(getMousePoint(m))
34 mousePointNum += 1
35 
36 while(mousePointNum == 1 or checkEndingPoint(mousePointArray[mousePointNum-2],mousePointArray[mousePointNum-1]) == True):
37     print(\"鼠标移动到第%d个点击点\"%(mousePointNum+1))
38     countDown(5)
39     mousePointArray.append(getMousePoint(m))
40     mousePointNum += 1
41 
42 while(times > 0):
43     click_idx = 0
44     while(click_idx < mousePointNum):
45         m.click(mousePointArray[click_idx][0],mousePointArray[click_idx][1], button=1, n=1)
46         print(\"点击坐标\",mousePointArray[click_idx])
47         time.sleep(1)
48         click_idx += 1
49     times -=1
50     print(\"剩余次数...%d\"%times)
51     time.sleep(timeWaitNextRun)

 


来源:https://www.cnblogs.com/Wokky/p/16909997.html
本站部分图文来源于网络,如有侵权请联系删除。

未经允许不得转载:百木园 » 为了删除数万封邮件,使用python模拟鼠标自动点击删除

相关推荐

  • 暂无文章