目的:作為中醫受益者向類似遭遇的朋友傳遞中醫訊息
工具:airtest
方式:百度病患類貼吧發多成網址的私信
過程:
手機連接電腦,模擬真人瀏覽貼吧主題,並向發貼人私信多成中醫網址,全程自動化操作。
更新:
最後最新程序日期是 2022年8月,由於貼吧app不斷更新,程序相應也要調整。
視頻演示:
代碼部份:
# -*- encoding=utf8 -*-
__author__ = "017207.com"
#airtest標準
from airtest.core.api import *
auto_setup(__file__)
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
class baidutieba:
def __init__(self, number):
self.number = number
self.begin = 0
def autosend(self):
while self.begin<=self.number:
#判斷是否有頭像存在
if poco(nameMatches=".*?的头像"):
for item in poco(nameMatches=".*?的头像"):
x,y = item.get_position()
#判斷頭像的位置
if 0.82> y >0.1:
print(item.attr("name"))
item.click()
sleep(3.0)
if exists(Template(r"tpl1660999861949.png", record_pos=(0.369, -0.536), resolution=(720, 1520))):
touch(Template(r"tpl1660999056021.png", record_pos=(0.367, -0.432), resolution=(720, 1520)))
# poco.click([0.86,0.245])
#判斷同一個人之前是否發過私信
if not poco(nameMatches="多成中醫[\s\S]*"):
poco("android.widget.EditText").click()
text("多成中醫網上醫院 https://www.duosuccess.com/ 希望有幫助",enter=False)
poco.click([0.879,0.912])
sleep(3.0)
keyevent("back")
self.begin += 1
print("发送成功第"+str(self.begin)+"次")
#如果發過就不再重發
else:
pass
print("已经发送过")
sleep(1.0)
for i in range(2):
keyevent("back")
sleep(1.0)
else:
keyevent("back")
sleep(5.0)
poco.swipe([0.5,0.8],[0.5,0.2])
else:
poco.swipe([0.5,0.8],[0.5,0.2])
if __name__ == '__main__':
number = int(20)#這里可以提前填入要循環的總次數
baidu = baidutieba(number)
baidu.autosend()
