
我只發Python腳本,別的什么都不說了!
因為很多人在問,這個不是什么高大上的玩意兒,發出來共同進步!我自己在用的,還只有這個穩定一點,別的什么其實都不好用。
需要自己截圖,存在程序同目錄下,就是通過圖片判斷,是否點擊和點擊位置。

Python源碼:
""" 當然在學習Python的道路上肯定會困難,沒有好的學習資料,怎么去學習呢? 學習Python中有不明白推薦加入交流Q群號:928946953 群里有志同道合的小伙伴,互幫互助, 群里有不錯的視頻學習教程和PDF! 還有大牛解答! """ #python 3.6.4 # encoding:utf-8 #確保已連接好adb #1080 2280 分辨率,一加6測試通過 #抖音版本20200618 import os import cv2 import sys import time import random from PIL import Image #pip install pillow import diannaoshuohua import zhaotu # 上傳照片到電腦 def screen(): # 截圖保存在手機上 os.system('adb shell screencap -p /sdcard/screen.png') # 傳到電腦上 os.system('adb pull /sdcard/screen.png') # 截圖,粉絲詳情頁圖片 def screen3(): # 截圖保存在手機上 os.system('adb shell screencap -p /sdcard/screen3.png') # 傳到電腦上 os.system('adb pull /sdcard/screen3.png') #處理照片 def getDistance(): #讀取圖片 image = Image.open('screen.png') #返回元組 width = image.size[0] height = image.size[1] #print(height,width) for i in range(803,804):#遍歷一個縱列 for j in range(0,height): if image.getpixel((i,j))[:3] == (179, 38, 69):#如果找到符合位置的顏色點,則確定了按鈕所在 yield j #生成器。返回所有找到的縱坐標的值 def jietu(mubiaotu): # 打開剛截取的全屏圖 img = Image.open(mubiaotu) # 定位到需要截取的地方 img = img.crop((0, 200, 1080, 1400)) # 截取成功並保存到本地 img.save('screen3_jietu.png') def as_num(x): y = '{:.10f}'.format(x) # .10f 保留10位小數 return y # 查找圖片 def findImg(target1,template2): #讀取目標圖片 target = cv2.imread(target1) #讀取模板圖片 template = cv2.imread(template2) #獲得模板圖片的高寬尺寸 theight,twidth = template.shape[:2] #執行模板匹配,采用的匹配方式cv2.TM_SQDIFF_NORMED result = cv2.matchTemplate(target,template,cv2.TM_SQDIFF_NORMED) cv2.normalize(result,result, 0, 1, cv2.NORM_MINMAX, -1 ) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) strmin_val = str(min_val) cv2.rectangle(target,min_loc,(min_loc[0]+twidth,min_loc[1]+theight),(0,0,225),2) print ("匹配最小值為:"+as_num(float(str(min_val)))) print ('匹配最大值為:'+as_num(float(str(max_val)))) r = int((image.getpixel((min_loc[0]+23,min_loc[1]+17)))[0]) if (abs(float(as_num(float(str(max_val))))) >= 0.9) and r > 180:#如果找到符合位置的顏色點: print ('找到符合的圖片') return True else: print('沒有找到符合的圖片') return False if __name__ == '__main__':#主函數開頭 i=0 n=0 sj = random.uniform(1,5) for _ in range(100): screen() print('截屏某用戶的粉絲列表') xy = zhaotu.findImg2('s.png','screen.png') for d in xy: screen() time.sleep(sj) os.system('adb shell input tap {} {}'.format(d[0],d[1])) time.sleep(sj) screen3()#個人詳情頁截圖 time.sleep(sj) jietu('screen3.png') time.sleep(sj) if zhaotu.findImg1('nv.png','screen3_jietu.png'): xy = zhaotu.findImg1('nv.png','screen3_jietu.png') image = Image.open("screen3_jietu.png")#打開個人詳情頁截圖 r = int((image.getpixel((xy[0],xy[1])))[0]) if (r > 180): print('找到一位女士,即將關注!') os.system('adb shell input tap 550 466')#點擊關注按鈕,暫用坐標,待完善 time.sleep(sj) os.system('adb shell input keyevent 4') time.sleep(sj) i=i+1 print('已關注了'+str(i)+'位女士') if i == 175: print('本次運行已關注198人,已退出運行!') diannaoshuohua.shuohua('本次已關注198人,即將退出!') os.system('adb shell input keyevent 26')#power事件。 sys.exit() else: os.system('adb shell input keyevent 4') #點擊后退按鈕 else: print('這不是女士,即將返回!') n=n+1 os.system('adb shell input keyevent 4') #點擊后退按鈕 #翻頁滑動按鈕 os.system('adb shell input swipe 548 1500 540 225 511') time.sleep(random.uniform(0.4, 0.8)) print('正在翻頁。。。') #zhaotu.py 調用方法:findImg('目標圖片地址','模板圖片地址') #findImg2----多目標匹配,返回的是生成器結果,需要for遍歷出單個結果 #findImg1----單目標匹配,返回圖片所在位置的中心點坐標值 import cv2 import numpy from PIL import Image def as_num(x): y = '{:.10f}'.format(x) # .10f 保留10位小數 return y def findImg2(target,template):#opencv模板匹配----多目標匹配 #讀取目標圖片 target = cv2.imread(target) #讀取模板圖片 template = cv2.imread(template) #獲得模板圖片的高寬尺寸 theight, twidth = template.shape[:2] #執行模板匹配,采用的匹配方式cv2.TM_SQDIFF_NORMED print(theight,twidth) result = cv2.matchTemplate(target,template,cv2.TM_SQDIFF_NORMED) #CV_TM_SQDIFF_NORMED min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) cv2.rectangle(target,min_loc,(min_loc[0]+twidth,min_loc[1]+theight),(0,0,225),2) strmin_val = str(min_val) #初始化位置參數 temp_loc = min_loc other_loc = min_loc numOfloc = 1 #第一次篩選----規定匹配閾值,將滿足閾值的從result中提取出來 #對於cv2.TM_SQDIFF及cv2.TM_SQDIFF_NORMED方法設置匹配閾值為0.01 threshold = 0.01 #這個值從0.01到0.05之間 loc = numpy.where(result<threshold) if loc: #遍歷提取出來的位置 for other_loc in zip(*loc[::-1]): #print(other_loc[0],other_loc[1]) yield other_loc else: return false # 查找設定的圖片是否包含在另一張圖片里 def findImg1(target1,template2):#傳入要查找的圖片地址和名稱,1為大圖,2為小圖,從大圖里查找小圖。 #讀取目標圖片 target = cv2.imread(target1) theight1,twidth1 = target.shape[:2] #讀取模板圖片 template = cv2.imread(template2) #獲得模板圖片的高寬尺寸 theight,twidth = template.shape[:2] #執行模板匹配,采用的匹配方式cv2.TM_SQDIFF_NORMED result = cv2.matchTemplate(target,template,cv2.TM_SQDIFF_NORMED) #歸一化處理 cv2.normalize(result,result, 0, 1, cv2.NORM_MINMAX, -1 ) #尋找矩陣(一維數組當做向量,用Mat定義)中的最大值和最小值的匹配結果及其位置 min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) #對於cv2.TM_SQDIFF及cv2.TM_SQDIFF_NORMED方法min_val越趨近與0匹配度越好,匹配位置取min_loc #對於其他方法max_val越趨近於1匹配度越好,匹配位置取max_loc strmin_val = str(min_val) #min_loc:矩形定點 cv2.rectangle(target,min_loc,(min_loc[0]+twidth,min_loc[1]+theight),(0,0,225),2) #顯示結果,並將匹配值顯示在標題欄上 print ("匹配最小值為:"+as_num(float(str(min_val)))) print ('匹配最大值為:'+as_num(float(str(max_val)))) if (abs(float(as_num(float(str(max_val))))) >= 0.9):# 如果找到 print ('找到符合的圖片') return min_loc[0]+twidth1/2,min_loc[1]+theight1/2 else: print('沒有找到符合的圖片') return False
有同學問寫腳本難不難學,我一直沒回復,想等個時間用最簡單明了的方式說明一下。
拿寫各種掛機腳本來說,其實非常簡單。如果有人說難,那就是准備忽悠你。
掛機腳本,用一句話說明白:讓程序去驅動手機,模擬人的動作,操作手機執行一定動作。
人有視覺,會思考判斷,知道下一步該干什么。而程序腳本一開始它是不知道的。所以你得告訴它。它呢,聽不懂人話,所以你得用程序語言來告訴它。
我們知道語言,有單詞和語法兩個重要的東西,掌握了這兩個,你就會說人話。比如“天”是單詞,“我抬頭看了看天”是語法句式。“我抬頭看了看天,發現天快要下雨了,我決定回家拿把傘”,這里就有思考和判斷,可以讓一個人不再是個傻。

所有的腳本編程語言,不管python,還是autojs,他們也都有自己的單詞和語法兩個東西。但是單詞和語法總量,就那么幾個,花兩三天時間就能瀏覽完,並稍加理解,如果記不住,到時用的時候查百度查文檔就行,這不是閉卷考試,你隨便翻書。只要兩三天時間,你以后就知道該怎么翻書偷看了。
接下來,你就會寫掛機腳本了,比如你要刷抖音粉絲。
當你想到你可以去關注一個人的粉絲列表下所有的人,這樣就有不少人也許會回關你。這個就是一開始的程序設計思路。這本身跟程序無關。
那么,你要寫的腳本就是,先到一個抖音用戶的粉絲列表頁,這個頁面有什么特征標識,你眼睛看得到,程序不知道啊,它只能通過頁面上有的東西來判斷,比如頁面上有什么圖形(這個叫找圖識圖,我的python腳本就是用的這種方式),或者頁面有什么元素,或者有什么文字之類的(autojs提供這種功能)。
當確定了一個粉絲列表頁,接下來就該去點擊每個“關注”按鈕了。一頁有10個“關注”按鈕,程序就得點10次,你就得用語法告訴程序,讓它按照你的設計來執行動作。
點完一個按鈕之后,為了防止抖音察覺有機器人在快速圈粉,你得裝作人類,點完一個按鈕要稍微停頓一下,這時你就可以用一個單詞,比如sleep(1000),這個表示程序執行到這里,暫停1000毫秒。
再說一遍,掌握這些單詞和語法,兩三天時間就夠了。
你不願意學,幾年,十幾年在原地打轉,那誰也沒辦法救你。
問python腳本的同學,我那個腳本需要你在本地配置好python環境。
截圖是截你要查找的標識圖片,或者你要點擊的按鈕圖片。如果不懂python那肯定有點蒙圈。
這個沒時間教了,有興趣自己查一下,不難的,一天把的事。