1. 程式人生 > 實用技巧 >監控多條微信公眾號連結閱讀量,並可視化--模擬滑鼠鍵盤

監控多條微信公眾號連結閱讀量,並可視化--模擬滑鼠鍵盤

  1 from time import sleep
  2 import random,pyperclip,os
  3 import pyautogui
  4 from openpyxl import load_workbook
  5 import datetime
  6 import tkinter as tk
  7 
  8 path = os.getcwd()+'\\URL連結.xlsx'
  9 wb = load_workbook(path)
 10 ws = wb.worksheets[0]
 11 
 12 sleep(1)
 13 pyautogui.FAILSAFE = True
14 15 width, height = pyautogui.size() 16 print(width,height) 17 18 cur_x, cur_y = pyautogui.position() 19 print(cur_x,cur_y) 20 21 def opation(): 22 def control(url,i,m): 23 pyautogui.click(x = 85, y = 1060, duration=2)#移動滑鼠工作列微信 24 pyautogui.click()#當前位置點選 25 sleep(1)
26 pyautogui.click(x=1063, y=744, duration=2) # 移動滑鼠輸入框 27 pyautogui.click() # 當前位置點選 28 29 pyautogui.typewrite(url, interval=0.25) # 輸入文字 30 pyautogui.press('space') 31 sleep(1) 32 pyautogui.press('enter') 33 # pyautogui.click(x=792, y=569, duration=2) # 移動滑鼠傳送
34 # pyautogui.click() # 當前位置點選 35 sleep(1) 36 pyautogui.click(x=1108, y=626, duration=2) # 移動滑鼠點選連結 37 pyautogui.click() # 當前位置點選 38 39 sleep(2) 40 pyautogui.click(x = 1258, y = 300, duration=2)#移動滑鼠文章空白位置 41 pyautogui.click()#當前位置點選 42 43 sleep(random.randint(3,6)) 44 pyautogui.hotkey('ctrl', 'a') # 組合按鍵(Ctrl+A)#全選 45 sleep(1) 46 pyautogui.hotkey('ctrl', 'c') # 組合按鍵(Ctrl+C)#複製 47 sleep(1) 48 text = pyperclip.paste() 49 # print(text) 50 if "閱讀 "in text: 51 index = text.index("閱讀 ") 52 click = text[index:] 53 for kw in click.split("\n"): 54 if "閱讀 " in kw: 55 print("閱讀:", kw.replace("閱讀", "").strip()) 56 # reads.append(kw.replace("閱讀", "").strip()) 57 ws.cell(i+1,3+m).value = kw.replace("閱讀", "").strip() 58 elif "在看" in kw: 59 print("在看:", kw.replace("在看", "").strip()) 60 sleep(1) 61 pyautogui.click(x=1260, y=150, duration=2) # 移動滑鼠"關閉"位置 62 pyautogui.click() # 當前位置點選 #關閉 63 # print(text)8CAA 64 wb.save(path) 65 66 for m in range(int(e1.get())): 67 now_time = datetime.datetime.now().strftime('%H:%M:%S') # %Y-%m-%d %H:%M:%S 68 ws.cell(1,3+m).value =now_time#監控連結的時間儲存 69 for i in range(1,ws.max_row): 70 # print(ws.cell(i+1,2).value) 71 # if len(ws.cell(i+1,2).value): 72 control(ws.cell(i+1,2).value,i,m) 73 74 75 #刪除原來的所有圖片檔案 76 file_names = os.listdir(os.getcwd() + '\\img\\') 77 for file_name in file_names: 78 os.remove(os.getcwd() + '\\img\\' + file_name) 79 #視覺化 80 import matplotlib.pyplot as plt 81 x_time = [] 82 for i in range(3, ws.max_column + 1): 83 x_time.append(ws.cell(1, i).value) 84 print(x_time) 85 for i in range(1, ws.max_row): 86 y_read = [] 87 for j in range(3, ws.max_column + 1): 88 y_read.append(ws.cell(i + 1, j).value) 89 plt.plot(x_time, y_read) 90 plt.title(ws.cell(i + 1, 2).value) 91 plt.savefig(os.getcwd() + '\\img\\' + str(i) + '.jpg') 92 plt.show() 93 94 l2 = tk.Label(win, text='監控完成,畫圖已儲存') 95 l2.pack() 96 97 if __name__ == '__main__': 98 win = tk.Tk() 99 win.title('監控微信文章閱讀量') 100 win.geometry('300x400') 101 l1 =tk.Label(win,text='輸入需要監控的多少個時間間隔:') 102 l1.pack() 103 e1 = tk.Entry(win,show=None) 104 e1.pack() 105 # l2 = tk.Label(win, text='輸入間隔的時長:(分鐘)') 106 # l2.pack() 107 # e2 = tk.Entry(win, show=None) 108 # e2.pack() 109 # 110 b = tk.Button(win,text='開始監控',width=12,height=1,command=opation) 111 b.pack() 112 113 win.mainloop()