前提:使用之前需要對抖音關注頁面進行截圖放在當前目錄下
import os from PIL import Image # pip install pillow import sys import time def Screen_cap(): #截屏 os.system("adb shell screencap -p /sdcard/screen.png") #保存圖片 os.system('adb pull /sdcard/screen.png') #橫坐標不變,縱坐標變 852 #長度 2340 852一直去遍歷2340 254,52,92 # 評論的內容 設置一個列表 打廣告之類的哈(要做停留,模擬停留) def Gety_position(): y_list = [] image = Image.open('screen.png') #得到當前目錄下的文件 for i in [852]: for y in range(2340): if image.getpixel((i,y)) == (254,52,92,255): #RGBA 表示三基色和透明度 print(y) y_list.append(y) return y_list for n in range(sys.maxsize): #截屏 Screen_cap() #得到y坐標 y_position = Gety_position() #模擬點擊 for y in y_position: os.system('adb shell input tap 852 {}'.format(y)) time.sleep(1) print('正在關注。。。。。。') #翻頁操作(根據手機的分辨率來設置) os.system('adb shell input swipe 540 2000 540 800') time.sleep(1)