| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | import datetimeimport randomimport timeimport requestsimport uiautomator2 as u2from tools.ip_util import get_local_ip, get_citydef dong_action(mobile, device_serial, keyword, content):    # 连接设备    d = u2.connect(device_serial)    d.healthcheck()    d.screen_on()    d.unlock()    d.debug = False    # 关闭app    d.app_stop('com.ss.android.auto')    # 启动app    d.app_start('com.ss.android.auto', use_monkey=True)    txt = content.split('+')    print('len', len(txt))    print('type', type(txt))    time.sleep(3)    '''    搜索、点赞、收藏、回帖    '''    d.xpath('//*[@resource-id="com.ss.android.auto:id/bug"]').click_exists()    d(focused=True).set_text(keyword)    time.sleep(2)    d.xpath('//*[@resource-id="com.ss.android.auto:id/fd4"]').click_exists()    time.sleep(3)    d.xpath('//*[@text="视频"]').click_exists()    time.sleep(1)    while 1:        # 视频点击        for elem in d.xpath('//android.view.View').all():            d.click(0.23, 0.261)            time.sleep(2)            # 点赞            d.xpath('//*[@resource-id="com.ss.android.auto:id/dxu"]/android.widget.ImageView[1]').click_exists()            time.sleep(1)            # 收藏            d.xpath('//*[@resource-id="com.ss.android.auto:id/d1z"]').click_exists()            time.sleep(2)            # 回帖            k = d.xpath('//*[@resource-id="com.ss.android.auto:id/j_b"]')            j = d(text='说点什么...')            if k:                k.click_exists()            if j:                j.click_exists()            time.sleep(3)            # d.xpath('//*[contains(name(), "EditText")]').click_exists()            d(focused=True).set_text(random.choice(txt))            # d.send_keys(t)            # print('text:', t)            m = d.xpath('//*[@resource-id="com.ss.android.auto:id/f6f"]')            # n = d(text='发布')            if m:                d.xpath('//*[@resource-id="com.ss.android.auto:id/f6f"]').click_exists()            # if n:            #     d(text='发布').click()            # time.sleep(3)            # d.click(0.479, 0.23)            # 返回            d.xpath('//*[@resource-id="com.ss.android.auto:id/de"]').click_exists()            #            d.swipe_ext('up', scale=0.265)            # mobile, operate_type, ip, content, operate_time, result, channel, city            ip = get_local_ip()            if ip is not None:                city = get_city(ip)            else:                ip = ''                city = ''            # mobile = '13816996346'            # 记录回帖数据            url = 'http://localhost:8066/backend/operate'            params = {"channel": "dongchedi", "city": city, "ip": ip, "mobile": mobile, "operateTime": datetime.datetime.now(), "operateType": "2", "result": "操作成功"}            response = requests.post(url, data=params)            if response.ok:                result = response.json()                print(result)            else:                print('请求失败:', response.status_code)def dongcd_stop(device_serial):    # 连接设备    d = u2.connect(device_serial)    d.healthcheck()    d.screen_on()    d.unlock()    d.debug = True    # 关闭app    d.app_stop('com.ss.android.auto')
 |