# 1.函數的作用域 # 全局變數的作用域: # 一般在函數體外定義的變數成為全局變數,在函數內部定義的變數稱為局部變數。 # 全局變數所有作用域都可用,局部變數只能在本函數可用,變 # 量的使用順序是,局部變數 > 全局變數, 也就是說:優先使用局部變數 # # global關鍵字: # 為瞭解決 ...
公司的企業郵箱有段時間不知道為啥沒有刪除伺服器上的郵件,屯了幾萬封。登陸企業郵網站,又不好清空郵箱,只能每次一頁刪除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)