├── img ├── fish_back.png ├── fish_open.png ├── fish_take.png ├── alipay_get.png ├── fish_advance.png ├── fish_close.png ├── fish_close2.png ├── fish_prize.png ├── fish_swing.png ├── fish_continue.png ├── fish_continue2.png └── fish_confirm_attend.png ├── requirements.txt ├── README.md ├── 淘宝多任务执行.py ├── 识别图片测试.py ├── chromedriver.py ├── 支付宝农场.py ├── .gitignore ├── 淘宝芭芭农场.py ├── 2024淘宝双11.py ├── 淘金币任务.py ├── 淘宝签到任务.py ├── 淘宝618活动.py ├── 2025淘宝双11.py ├── utils.py ├── LICENSE └── 闲鱼任务.py /img/fish_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_back.png -------------------------------------------------------------------------------- /img/fish_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_open.png -------------------------------------------------------------------------------- /img/fish_take.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_take.png -------------------------------------------------------------------------------- /img/alipay_get.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/alipay_get.png -------------------------------------------------------------------------------- /img/fish_advance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_advance.png -------------------------------------------------------------------------------- /img/fish_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_close.png -------------------------------------------------------------------------------- /img/fish_close2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_close2.png -------------------------------------------------------------------------------- /img/fish_prize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_prize.png -------------------------------------------------------------------------------- /img/fish_swing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_swing.png -------------------------------------------------------------------------------- /img/fish_continue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_continue.png -------------------------------------------------------------------------------- /img/fish_continue2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_continue2.png -------------------------------------------------------------------------------- /img/fish_confirm_attend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czl0325/coin11-tb/HEAD/img/fish_confirm_attend.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | uiautodev==0.14.0 2 | uiautomator2==3.5.0 3 | pytesseract==0.3.13 4 | opencv-python==4.12.0.88 5 | ddddocr==1.5.6 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # coin11-tb 2 | 使用uiautomator2自动化完成2024年淘宝双11的金币任务,淘金币任务,芭芭农场任务,闲鱼任务。 3 | 4 | 需要安装adb,自行百度教程。 5 | 使用教程请看抖音 6 | ``` 7 | 3.53 04/14 X@z.TY bnD:/ 自动化完成淘宝任务教程 https://v.douyin.com/i5xNsWVx/ 复制此链接,打开Dou音搜索,直接观看视频! 8 | ``` 9 | 或者快手 10 | ``` 11 | https://v.kuaishou.com/nGmUFX 自动化完成淘宝任务教程 该作品在快手被播放过1次,点击链接,打开【快手极速版】直接观看! 12 | ``` 13 | 14 | * 使用uiauto.dev查看ui组件 15 | ``` 16 | pip3 install uiautodev 17 | # 启动 18 | uiauto.dev 19 | ``` 20 | 21 | adb命令,获取当前打开的app包名和类名 22 | ```shell 23 | adb shell dumpsys window | grep mCurrentFocus 24 | adb shell dumpsys window | findstr mCurrentFocus 25 | ``` 26 | 27 | 目前淘宝芭芭农场和淘金币任务相对完善,其他的还有问题。 28 | $\color{red}{目前的问题是,uiautomator2将列表上滑一页后,获取的数据还是上一页的,这个问题已反馈作者但未解决。}$ 29 | 30 | ```shell 31 | adb shell screencap -p /sdcard/screenshot.png 32 | adb pull /sdcard/screenshot.png . 33 | adb shell rm /sdcard/screenshot.png 34 | ``` 35 | 36 | ```shell 37 | adb shell uiautomator dump /sdcard/window_dump.xml 38 | adb pull /sdcard/window_dump.xml . 39 | adb shell rm /sdcard/window_dump.xml 40 | ``` -------------------------------------------------------------------------------- /淘宝多任务执行.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import sys 3 | import os 4 | 5 | 6 | def run_scripts(script_paths): 7 | python_executable = sys.executable 8 | for script in script_paths: 9 | if not os.path.exists(script): 10 | print(f"警告: 脚本文件 '{script}' 不存在,跳过执行") 11 | continue 12 | print(f"开始执行: {script}") 13 | try: 14 | # 执行脚本,等待完成后再执行下一个 15 | result = subprocess.run( 16 | [python_executable, script], 17 | check=True, 18 | stdout=sys.stdout, # 子进程stdout直接指向当前进程的stdout 19 | stderr=sys.stderr, # 子进程stderr直接指向当前进程的stderr 20 | text=True 21 | ) 22 | # 打印脚本输出 23 | if result.stdout: 24 | print(f"输出:{result.stdout}") 25 | print(f"执行成功: {script}") 26 | except subprocess.CalledProcessError as e: 27 | print(f"执行失败: {script}") 28 | print(f"错误信息: {e.stderr}") 29 | 30 | 31 | if __name__ == "__main__": 32 | scripts_to_run = [ 33 | "淘宝芭芭农场.py", 34 | "淘金币任务.py", 35 | "支付宝农场.py", 36 | # "闲鱼任务.py", 37 | ] 38 | 39 | run_scripts(scripts_to_run) 40 | -------------------------------------------------------------------------------- /识别图片测试.py: -------------------------------------------------------------------------------- 1 | import ddddocr 2 | import cv2 3 | from PIL import Image 4 | 5 | 6 | def practical_example(): 7 | """ 8 | 实际应用示例:识别图片中的特定信息 9 | """ 10 | # 初始化OCR 11 | det_ocr = ddddocr.DdddOcr(det=True, show_ad=False) 12 | rec_ocr = ddddocr.DdddOcr(show_ad=False) 13 | 14 | image_path = "screenshot.png" 15 | 16 | with open(image_path, 'rb') as f: 17 | image_bytes = f.read() 18 | 19 | # 检测所有文字区域 20 | bboxes = det_ocr.detection(image_bytes) 21 | 22 | # 按位置排序(从上到下,从左到右) 23 | bboxes.sort(key=lambda bbox: (bbox[1], bbox[0])) # 先按y坐标,再按x坐标排序 24 | 25 | # 识别每个区域的文字 26 | img_pil = Image.open(image_path) 27 | recognized_text = [] 28 | 29 | for i, bbox in enumerate(bboxes): 30 | x1, y1, x2, y2 = bbox 31 | cropped = img_pil.crop((x1, y1, x2, y2)) 32 | 33 | # 使用BytesIO进行识别 34 | from io import BytesIO 35 | img_byte_arr = BytesIO() 36 | cropped.save(img_byte_arr, format='PNG') 37 | 38 | text = rec_ocr.classification(img_byte_arr.getvalue()) 39 | recognized_text.append({ 40 | 'text': text, 41 | 'position': bbox, 42 | 'area': (x2 - x1) * (y2 - y1) 43 | }) 44 | 45 | # 输出整理后的结果 46 | print("=== 图片文字识别结果 ===") 47 | for i, item in enumerate(recognized_text): 48 | print(f"{i + 1:2d}. 位置: {item['position']} | 文字: '{item['text']}'") 49 | 50 | return recognized_text 51 | 52 | 53 | # 运行示例 54 | results = practical_example() 55 | print(results) -------------------------------------------------------------------------------- /chromedriver.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # extension for https://sites.google.com/a/chromium.org/chromedriver/ 5 | # Experimental, maybe change in the future 6 | # Created by 2017-01-20 7 | 8 | from __future__ import absolute_import 9 | 10 | import atexit 11 | from selenium import webdriver 12 | 13 | import subprocess 14 | from urllib.error import URLError 15 | 16 | 17 | class ChromeDriver(object): 18 | def __init__(self, d, port=9515): 19 | self._d = d 20 | self._port = port 21 | 22 | def _launch_webdriver(self): 23 | print("start chromedriver instance") 24 | p = subprocess.Popen(['chromedriver', '--port=' + str(self._port)]) 25 | try: 26 | p.wait(timeout=2.0) 27 | return False 28 | except subprocess.TimeoutExpired: 29 | return True 30 | 31 | def driver(self, package=None, attach=True, activity=None, process=None): 32 | """ 33 | Args: 34 | - package(string): default current running app 35 | - attach(bool): default true, Attach to an already-running app instead of launching the app with a clear data directory 36 | - activity(string): Name of the Activity hosting the WebView. 37 | - process(string): Process name of the Activity hosting the WebView (as given by ps). 38 | If not given, the process name is assumed to be the same as androidPackage. 39 | 40 | Returns: 41 | selenium driver 42 | """ 43 | app = self._d.current_app() 44 | capabilities = { 45 | 'chromeOptions': { 46 | 'androidDeviceSerial': self._d.serial, 47 | 'androidPackage': package or app["package"], 48 | 'androidUseRunningApp': attach, 49 | 'androidProcess': process or app["package"], 50 | 'androidActivity': activity or app["activity"], 51 | } 52 | } 53 | 54 | try: 55 | dr = webdriver.Remote('http://localhost:%d' % self._port, capabilities) 56 | except URLError: 57 | self._launch_webdriver() 58 | dr = webdriver.Remote('http://localhost:%d' % self._port, capabilities) 59 | 60 | # always quit driver when done 61 | atexit.register(dr.quit) 62 | return dr 63 | 64 | def windows_kill(self): 65 | subprocess.call(['taskkill', '/F', '/IM', 'chromedriver.exe', '/T']) 66 | 67 | 68 | if __name__ == '__main__': 69 | import atx 70 | 71 | d = atx.connect() 72 | driver = ChromeDriver(d).driver() 73 | elem = driver.find_element_by_link_text(u"登录") 74 | elem.click() 75 | driver.quit() -------------------------------------------------------------------------------- /支付宝农场.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import uiautomator2 as u2 4 | from uiautomator2 import Direction 5 | from utils import check_chars_exist, get_current_app, task_loop, ALIPAY_APP 6 | 7 | time1 = time.time() 8 | unclick_btn = [] 9 | is_end = False 10 | in_other_app = False 11 | d = u2.connect() 12 | d.app_start(ALIPAY_APP, stop=True, use_monkey=True) 13 | time.sleep(5) 14 | screen_width, screen_height = d.window_size() 15 | have_clicked = {} 16 | 17 | 18 | def check_in_task(): 19 | package_name, _ = get_current_app(d) 20 | if package_name != ALIPAY_APP: 21 | return False 22 | if d(className="android.widget.TextView", text="做任务集肥料").exists: 23 | return True 24 | return False 25 | 26 | 27 | d.watcher.when("O1CN012qVB9n1tvZ8ATEQGu_!!6000000005964-2-tps-144-144").click() 28 | d.watcher.when(xpath="//android.app.Dialog//android.widget.Button[@text='关闭']").click() 29 | d.watcher.start() 30 | while True: 31 | farm_btn = d(resourceId="com.alipay.android.phone.openplatform:id/app_text", className="android.widget.TextView", text="芭芭农场") 32 | if farm_btn.exists: 33 | print("点击芭芭农场按钮,进入芭芭农场首页") 34 | farm_btn.click() 35 | time.sleep(5) 36 | task_btn = d(className="android.widget.Button", text="任务列表") 37 | if task_btn.exists: 38 | print("点击任务列表", task_btn.center()[0], task_btn.center()[1]) 39 | task_btn.click() 40 | time.sleep(5) 41 | if check_in_task(): 42 | break 43 | finish_count = 0 44 | error_count = 0 45 | while True: 46 | try: 47 | time.sleep(3) 48 | get_btn = d(className="android.widget.Button", text="领取") 49 | if get_btn.exists: 50 | get_btn.click() 51 | time.sleep(2) 52 | to_btn = d.xpath('//android.widget.Button[@text="去逛逛" or @text="去完成"]') 53 | if to_btn.exists: 54 | print("去完成按钮存在") 55 | need_click_view = None 56 | need_click_name = "" 57 | for index, view in enumerate(to_btn.all()): 58 | name_view = d.xpath(f'(//android.widget.Button[@text="去逛逛" or @text="去完成"])[{index+1}]/parent::android.view.View/preceding-sibling::android.view.View[1]') 59 | if name_view.exists: 60 | name_text = name_view.text 61 | print(f"查找到任务:{name_text}") 62 | if check_chars_exist(name_text): 63 | continue 64 | if have_clicked.get(name_text): 65 | have_clicked[name_text] += 1 66 | else: 67 | have_clicked[name_text] = 1 68 | if have_clicked.get(name_text) > 2: 69 | continue 70 | need_click_view = view 71 | need_click_name = name_text 72 | break 73 | if need_click_view: 74 | need_click_view.click() 75 | print(f"点击按钮:{need_click_name}") 76 | time.sleep(4) 77 | task_loop(d, check_in_task, origin_app=ALIPAY_APP) 78 | finish_count = finish_count + 1 79 | else: 80 | error_count += 1 81 | print("未找到可点击按钮", error_count) 82 | if error_count >= 2: 83 | break 84 | else: 85 | print("没有查找到去完成按钮,退出循环") 86 | break 87 | except Exception as e: 88 | print(e) 89 | continue 90 | d.watcher.remove() 91 | print(f"共自动化完成{finish_count}个任务") 92 | d.shell("settings put system accelerometer_rotation 0") 93 | print("关闭手机自动旋转") 94 | time2 = time.time() 95 | minutes, seconds = divmod(int(time2 - time1), 60) # 同时计算分钟和秒 96 | print(f"共耗时: {minutes} 分钟 {seconds} 秒") 97 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 110 | .pdm.toml 111 | .pdm-python 112 | .pdm-build/ 113 | 114 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 115 | __pypackages__/ 116 | 117 | # Celery stuff 118 | celerybeat-schedule 119 | celerybeat.pid 120 | 121 | # SageMath parsed files 122 | *.sage.py 123 | 124 | # Environments 125 | .env 126 | .venv 127 | env/ 128 | venv/ 129 | ENV/ 130 | env.bak/ 131 | venv.bak/ 132 | 133 | # Spyder project settings 134 | .spyderproject 135 | .spyproject 136 | 137 | # Rope project settings 138 | .ropeproject 139 | 140 | # mkdocs documentation 141 | /site 142 | 143 | # mypy 144 | .mypy_cache/ 145 | .dmypy.json 146 | dmypy.json 147 | 148 | # Pyre type checker 149 | .pyre/ 150 | 151 | # pytype static type analyzer 152 | .pytype/ 153 | 154 | # Cython debug symbols 155 | cython_debug/ 156 | 157 | # PyCharm 158 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 159 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 160 | # and can be added to the global gitignore or merged into this file. For a more nuclear 161 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 162 | .idea/ 163 | .DS_Store 164 | -------------------------------------------------------------------------------- /淘宝芭芭农场.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import uiautomator2 as u2 4 | from uiautomator2 import Direction 5 | from utils import check_chars_exist, other_app, get_current_app, task_loop, select_device, check_verify 6 | 7 | unclick_btn = [] 8 | have_clicked = dict() 9 | is_end = False 10 | error_count = 0 11 | in_other_app = False 12 | time1 = time.time() 13 | selected_device = select_device() 14 | d = u2.connect(selected_device) 15 | print(f"已成功连接设备:{selected_device}") 16 | d.app_start("com.taobao.taobao", stop=True, use_monkey=True) 17 | screen_width, screen_height = d.window_size() 18 | time.sleep(5) 19 | # https://dl.ncat1.app/ 20 | 21 | 22 | def check_in_task(): 23 | package_name, _ = get_current_app(d) 24 | if package_name != "com.taobao.taobao": 25 | return False 26 | if d(className="android.widget.TextView", text="肥料明细").exists: 27 | return True 28 | return False 29 | 30 | 31 | # 查找芭芭农场按钮 32 | def find_farm_btn(): 33 | print("开始查找芭芭农场按钮") 34 | no_found_count = 0 35 | while True: 36 | farm_btn = d(className="android.widget.FrameLayout", description="芭芭农场") 37 | if farm_btn.exists(timeout=5): 38 | farm_btn.click() 39 | time.sleep(12) 40 | temp_btn = d(className="android.widget.Button", textContains="集肥料") 41 | new_ui = d(resourceId="game-canvas-fuguo", className="android.widget.Image") 42 | if temp_btn.exists or new_ui.exists: 43 | break 44 | 45 | 46 | # 查找集肥料按钮 47 | def find_fertilizer_btn(): 48 | print("开始查找集肥料按钮...") 49 | while True: 50 | fertilize_btn = d(className="android.widget.Button", textContains="集肥料") 51 | if fertilize_btn.click_exists(timeout=2): 52 | print("点击集肥料按钮") 53 | time.sleep(12) 54 | if check_in_task(): 55 | break 56 | else: 57 | new_ui = d(resourceId="game-canvas-fuguo", className="android.widget.Image") 58 | if new_ui.exists: 59 | print(f"点击靠近的集肥料按钮, {screen_width * 0.7}, {new_ui.bounds()[3] - 50}") 60 | d.click(screen_width * 0.7, new_ui.bounds()[3] - 50) 61 | time.sleep(12) 62 | if check_in_task(): 63 | break 64 | print("进入任务页面") 65 | 66 | 67 | d.watcher.when("O1CN012qVB9n1tvZ8ATEQGu_!!6000000005964-2-tps-144-144").click() 68 | d.watcher.when(xpath="//android.app.Dialog//android.widget.Button[contains(text(), '-tps-')]").click() 69 | d.watcher.when(xpath="//android.app.Dialog//android.widget.Button[@text='关闭']").click() 70 | d.watcher.when(xpath="//android.widget.FrameLayout[@resource-id='com.taobao.taobao:id/poplayer_native_state_center_layout_frame_id']//android.widget.ImageView[@content-desc='关闭按钮']").click() 71 | # d.watcher.when(xpath="//android.widget.TextView[@package='com.eg.android.AlipayGphone']").click() 72 | d.watcher.when("O1CN01sORayC1hBVsDQRZoO_!!6000000004239-2-tps-426-128.png_").click() 73 | d.watcher.when("跳过").click() 74 | d.watcher.when("点击刷新").click() 75 | d.watcher.when("点击重试").click() 76 | # d.watcher.when("关闭").click() 77 | d.watcher.start() 78 | find_farm_btn() 79 | find_fertilizer_btn() 80 | finish_count = 0 81 | while True: 82 | try: 83 | print("开始查找按钮") 84 | check_verify(d) 85 | time.sleep(4) 86 | in_other_app = False 87 | sign_btn = d(className="android.widget.Button", text="去签到") 88 | if sign_btn.exists: 89 | sign_btn.click() 90 | time.sleep(2) 91 | to_btn = d(className="android.widget.Button", textMatches="去完成|去浏览|去领取") 92 | if to_btn.exists: 93 | need_click_view = None 94 | need_click_index = 0 95 | task_name = None 96 | for index, view in enumerate(to_btn): 97 | text_div = view.sibling(className="android.view.View", instance=0).child(className="android.widget.TextView", instance=0) 98 | if text_div.exists: 99 | if check_chars_exist(text_div.get_text(), ["游戏", "一元抢", "开通", "搜索兴趣商品下单", "买精选商品", "1元抢", "下单", "淘宝秒杀", "消消乐", "3元3件", "中国移动", "百度地图"]): 100 | if view not in unclick_btn: 101 | unclick_btn.append(view) 102 | continue 103 | task_name = text_div.get_text() 104 | if task_name in have_clicked: 105 | if have_clicked[task_name] >= 2: 106 | continue 107 | need_click_index = index 108 | need_click_view = view 109 | break 110 | if need_click_view: 111 | print("点击按钮", task_name) 112 | if have_clicked.get(task_name) is None: 113 | have_clicked[task_name] = 1 114 | else: 115 | have_clicked[task_name] += 1 116 | if check_chars_exist(task_name, other_app): 117 | in_other_app = True 118 | need_click_view.click() 119 | time.sleep(4) 120 | task_loop(d, check_in_task) 121 | finish_count = finish_count + 1 122 | else: 123 | error_count += 1 124 | print("未找到可点击按钮", error_count) 125 | if error_count >= 2: 126 | break 127 | except Exception as e: 128 | print(e) 129 | continue 130 | d.watcher.remove() 131 | print(f"共自动化完成{finish_count}个任务") 132 | d.shell("settings put system accelerometer_rotation 0") 133 | print("关闭手机自动旋转") 134 | time2 = time.time() 135 | minutes, seconds = divmod(int(time2 - time1), 60) # 同时计算分钟和秒 136 | print(f"共耗时: {minutes} 分钟 {seconds} 秒") 137 | -------------------------------------------------------------------------------- /2024淘宝双11.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import uiautomator2 as u2 4 | from uiautomator2 import Direction 5 | from utils import check_chars_exist, other_app 6 | 7 | d = u2.connect() 8 | d.app_start("com.taobao.taobao", stop=True, use_monkey=True) 9 | # d.debug = True 10 | screen_width = d.info['displayWidth'] 11 | screen_height = d.info['displayHeight'] 12 | time.sleep(2) 13 | in_search = False 14 | in_other_app = False 15 | have_clicked = [] 16 | 17 | 18 | def check_close(): 19 | d(className="android.widget.Button", text="关闭") 20 | 21 | 22 | def operate_task(): 23 | global in_search 24 | global in_other_app 25 | start_time = time.time() 26 | taolive_btn = d(resourceId="com.taobao.taobao:id/taolive_close_btn") 27 | if taolive_btn.exists and not in_other_app: 28 | time.sleep(20) 29 | while True: 30 | taolive_btn = d(resourceId="com.taobao.taobao:id/taolive_close_btn") 31 | if not taolive_btn.exists: 32 | break 33 | d.press("back") 34 | time.sleep(5) 35 | elif in_other_app: 36 | time.sleep(10) 37 | print("当前包名: ", d.app_current()["package"]) 38 | d.app_stop(d.app_current()["package"]) 39 | in_other_app = False 40 | else: 41 | while True: 42 | if time.time() - start_time > 20: 43 | break 44 | d.swipe_ext(Direction.FORWARD) 45 | time.sleep(3) 46 | d.swipe_ext(Direction.BACKWARD) 47 | time.sleep(3) 48 | d.press("back") 49 | if in_search: 50 | time.sleep(2) 51 | in_search = False 52 | d.press("back") 53 | 54 | 55 | ctx = d.watch_context() 56 | ctx.when("O1CN012qVB9n1tvZ8ATEQGu_!!6000000005964-2-tps-144-144").click() 57 | ctx.when("O1CN01TkBa3v1zgLfbNmfp7_!!6000000006743-2-tps-72-72").click() 58 | ctx.when(xpath="//android.app.Dialog//android.widget.Button[@text='关闭']").click() 59 | # d.watcher.when(xpath="//android.widget.Button[@text='关闭']").click() 60 | # d.watcher.when("关闭").click() 61 | ctx.when(xpath="//android.widget.TextView[@package='com.eg.android.AlipayGphone']").click() 62 | ctx.start() 63 | # close_btn = d(className="android.widget.ImageView", description="关闭按钮") 64 | # if close_btn.exists: 65 | # close_btn.click() 66 | print("检查弹窗开始") 67 | ctx.wait_stable() 68 | print("检查弹窗结束") 69 | coin_btn = d(className="android.widget.FrameLayout", description="金币双11", clickable=True) 70 | if coin_btn.exists(timeout=10): 71 | d.click(coin_btn[0].center()[0], coin_btn[0].center()[1]) 72 | time.sleep(2) 73 | else: 74 | raise Exception("没有找到金币双11按钮") 75 | # task_btn = d.xpath('//android.widget.TextView[@text="做任务攒钱"]') 76 | while True: 77 | time.sleep(2) 78 | underway_btn = d(text="进行中") 79 | if underway_btn.exists: 80 | continue 81 | task_btn = d(text="做任务攒钱") 82 | if task_btn.exists: 83 | break 84 | # task_btn = d(resourceId="eva-canvas") 85 | error_count = 0 86 | if task_btn.click_exists(timeout=10): 87 | print("点击了做任务攒钱按钮") 88 | # left, bottom, right = task_btn.info['bounds']['left'], task_btn.info['bounds']['bottom'], task_btn.info['bounds']['right'] 89 | # d.click((right - left) // 2, bottom - 10) 90 | time.sleep(8) 91 | sign_btn = d(text="签到") 92 | if sign_btn.exists: 93 | sign_btn.click() 94 | time.sleep(2) 95 | # list_view = d(className="android.widget.ListView", instance=0) 96 | # print("检查list_view") 97 | # if list_view.exists: 98 | # print("list_view存在") 99 | unclick_btn = [] 100 | is_end = False 101 | while True: 102 | to_btn = d(className="android.widget.Button", text="去完成") 103 | if to_btn.exists: 104 | need_click_view = None 105 | need_click_index = 0 106 | task_name = None 107 | for index, view in enumerate(to_btn): 108 | text_div = view.sibling(className="android.view.View", instance=0).child(className="android.widget.TextView", instance=0) 109 | if text_div.exists: 110 | if check_chars_exist(text_div.get_text()): 111 | if view not in unclick_btn: 112 | unclick_btn.append(view) 113 | continue 114 | task_name = text_div.get_text() 115 | if task_name in have_clicked: 116 | continue 117 | need_click_index = index 118 | need_click_view = view 119 | break 120 | if need_click_view: 121 | print("点击按钮", task_name) 122 | if task_name not in have_clicked: 123 | have_clicked.append(task_name) 124 | need_click_view.click() 125 | time.sleep(2) 126 | search_view = d(className="android.view.View", text="搜索有福利") 127 | if search_view.exists: 128 | d(className="android.widget.EditText", instance=0).send_keys("笔记本电脑") 129 | d(className="android.widget.Button", text="搜索").click() 130 | in_search = True 131 | time.sleep(2) 132 | if check_chars_exist(task_name, other_app): 133 | in_other_app = True 134 | operate_task() 135 | else: 136 | web_view = d(className="android.webkit.WebView") 137 | if web_view.exists(timeout=5): 138 | operate_task() 139 | else: 140 | if not is_end: 141 | d.swipe_ext(Direction.FORWARD) 142 | d(scrollable=True).scroll.toEnd() 143 | is_end = True 144 | else: 145 | error_count += 1 146 | print("未找到可点击按钮", error_count) 147 | if error_count > 6: 148 | break 149 | else: 150 | print("没有找到去完成按钮") 151 | break 152 | time.sleep(6) 153 | else: 154 | print("未找到做任务按钮") 155 | draw_down_btn = d(className="android.widget.Button", text="立即领取") 156 | while True: 157 | if draw_down_btn.exists: 158 | draw_down_btn.click() 159 | time.sleep(2) 160 | else: 161 | break 162 | ctx.stop() 163 | ctx.close() 164 | d.watcher.remove() 165 | -------------------------------------------------------------------------------- /淘金币任务.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import uiautomator2 as u2 4 | from utils import check_chars_exist, other_app, get_current_app, select_device, task_loop, check_verify 5 | 6 | unclick_btn = [] 7 | have_clicked = dict() 8 | is_end = False 9 | error_count = 0 10 | in_other_app = False 11 | time1 = time.time() 12 | selected_device = select_device() 13 | d = u2.connect(selected_device) 14 | print(f"已成功连接设备:{selected_device}") 15 | d.shell("adb kill-server && adb start-server") 16 | time.sleep(5) 17 | # d.app_stop("com.taobao.taobao") 18 | # d.app_clear('com.taobao.taobao') 19 | # time.sleep(2) 20 | d.app_start("com.taobao.taobao", stop=True, use_monkey=True) 21 | ctx = d.watch_context() 22 | ctx.when("O1CN012qVB9n1tvZ8ATEQGu_!!6000000005964-2-tps-144-144").click() 23 | ctx.when("O1CN01sORayC1hBVsDQRZoO_!!6000000004239-2-tps-426-128.png_").click() 24 | ctx.when("领取今日奖励").click() 25 | ctx.when("确认").click() 26 | ctx.when("确定").click() 27 | ctx.when("点击刷新").click() 28 | ctx.when(xpath="//android.app.Dialog//android.widget.Button[contains(text(), '-tps-')]").click() 29 | ctx.when(xpath="//android.app.Dialog//android.widget.Button[@text='关闭']").click() 30 | ctx.when(xpath="//android.widget.FrameLayout[@resource-id='com.taobao.taobao:id/poplayer_native_state_center_layout_frame_id']//android.widget.ImageView[@content-desc='关闭按钮']").click() 31 | # ctx.when(xpath="//android.widget.TextView[@package='com.eg.android.AlipayGphone']").click() 32 | ctx.start() 33 | time.sleep(3) 34 | 35 | 36 | def check_in_task(): 37 | package, _ = get_current_app(d) 38 | if package == "com.taobao.taobao" and (d(className="android.widget.TextView", text="赚金币抵钱").exists or d(className="android.widget.TextView", text="今日累计奖励").exists): 39 | return True 40 | return False 41 | 42 | 43 | def find_coin_btn(): 44 | coin_btn = d(className="android.widget.FrameLayout", description="领淘金币", clickable=True) 45 | if coin_btn.exists: 46 | d.double_click(coin_btn[0].center()[0], coin_btn[0].center()[1]) 47 | time.sleep(5) 48 | else: 49 | d(className="android.view.View", description="搜索栏").click() 50 | d(resourceId="com.taobao.taobao:id/searchEdit").send_keys("淘金币") 51 | time.sleep(3) 52 | d(className="android.view.View", descriptionContains="淘金币").click() 53 | time.sleep(5) 54 | 55 | 56 | ctx.wait_stable() 57 | close_btn = d(className="android.widget.ImageView", description="关闭按钮") 58 | if close_btn and close_btn.exists: 59 | close_btn.click() 60 | time.sleep(3) 61 | find_coin_btn() 62 | 63 | # 因2025双十一活动,需要回旧版本后继续任务 64 | earn_btn = d(className="android.widget.Button", textContains="回日常版") 65 | if earn_btn.exists(timeout=4): 66 | earn_btn.click() 67 | time.sleep(3) 68 | earn_btn = d(className="android.widget.TextView", textMatches="签到领金币|点击签到") 69 | if earn_btn.exists(timeout=4): 70 | earn_btn.click() 71 | time.sleep(5) 72 | earn_btn = d(className="android.widget.TextView", textContains="赚更多金币") 73 | if earn_btn.exists(timeout=4): 74 | earn_btn.click() 75 | time.sleep(3) 76 | else: 77 | raise Exception("没有找到金币任务按钮") 78 | print("点击开始做任务") 79 | finish_count = 0 80 | while True: 81 | try: 82 | in_other_app = False 83 | time.sleep(4) 84 | check_verify(d) 85 | earn_btn = d(className="android.widget.TextView", text="赚更多金币") 86 | if earn_btn.exists and not d(className="android.widget.TextView", text="赚金币抵钱").exists: 87 | earn_btn.click() 88 | time.sleep(2) 89 | continue 90 | draw_down_btn = d(className="android.widget.Button", text="立即领取") 91 | if draw_down_btn.exists: 92 | draw_down_btn.click() 93 | time.sleep(2) 94 | print("开始查找按钮。。。") 95 | get_btn = d(className="android.widget.Button", text="领取奖励") 96 | if get_btn.exists: 97 | get_btn.click() 98 | print("点击领取奖励") 99 | time.sleep(2) 100 | # finish_count = finish_count + 1 101 | # if finish_count % 20 == 0: 102 | # d.swipe_ext("up", scale=0.2) 103 | # time.sleep(4) 104 | continue 105 | de_btn = d(className="android.widget.Button", text="点击得") 106 | if de_btn.exists: 107 | de_btn.click() 108 | print("点击点击得") 109 | time.sleep(4) 110 | continue 111 | to_btn = d(className="android.widget.Button", textMatches="去完成|去逛逛|去浏览|逛一逛|立即领|去领取|去看看|搜一下|玩一把|捐一笔|逛一下") 112 | if to_btn.exists: 113 | need_click_view = None 114 | need_click_index = 0 115 | task_name = None 116 | for index, view in enumerate(to_btn): 117 | text_div = view.sibling(className="android.view.View", instance=0).child(className="android.widget.TextView", instance=0) 118 | if text_div.exists: 119 | task_name = text_div.get_text() 120 | if check_chars_exist(task_name): 121 | if view not in unclick_btn: 122 | unclick_btn.append(view) 123 | continue 124 | if task_name in have_clicked: 125 | if have_clicked[task_name] >= 2: 126 | continue 127 | need_click_index = index 128 | need_click_view = view 129 | break 130 | if need_click_view: 131 | print("点击按钮", task_name) 132 | if have_clicked.get(task_name) is None: 133 | have_clicked[task_name] = 1 134 | else: 135 | have_clicked[task_name] += 1 136 | if check_chars_exist(task_name, other_app): 137 | in_other_app = True 138 | need_click_view.click() 139 | time.sleep(3.5) 140 | task_loop(d, check_in_task) 141 | else: 142 | error_count += 1 143 | print("未找到可点击按钮", error_count) 144 | if error_count >= 2: 145 | break 146 | except Exception as e: 147 | print(e) 148 | continue 149 | ctx.close() 150 | print(f"共自动化完成{finish_count}个任务") 151 | d.shell("settings put system accelerometer_rotation 0") 152 | print("关闭手机自动旋转") 153 | time2 = time.time() 154 | minutes, seconds = divmod(int(time2 - time1), 60) # 同时计算分钟和秒 155 | print(f"共耗时: {minutes} 分钟 {seconds} 秒") 156 | -------------------------------------------------------------------------------- /淘宝签到任务.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import uiautomator2 as u2 4 | from uiautomator2 import Direction 5 | from utils import check_chars_exist, other_app, get_current_app 6 | 7 | unclick_btn = [] 8 | have_clicked = dict() 9 | is_end = False 10 | error_count = 0 11 | in_other_app = False 12 | time1 = time.time() 13 | d = u2.connect() 14 | d.app_start("com.taobao.taobao", stop=True, use_monkey=True) 15 | ctx = d.watch_context() 16 | ctx.when("O1CN012qVB9n1tvZ8ATEQGu_!!6000000005964-2-tps-144-144").click() 17 | ctx.when("O1CN01sORayC1hBVsDQRZoO_!!6000000004239-2-tps-426-128.png_").click() 18 | ctx.when("领取今日奖励").click() 19 | ctx.when("确认").click() 20 | ctx.when("确定").click() 21 | ctx.when("点击刷新").click() 22 | ctx.when(xpath="//android.app.Dialog//android.widget.Button[contains(text(), '-tps-')]").click() 23 | ctx.when(xpath="//android.app.Dialog//android.widget.Button[@text='关闭']").click() 24 | ctx.when(xpath="//android.widget.FrameLayout[@resource-id='com.taobao.taobao:id/poplayer_native_state_center_layout_frame_id']//android.widget.ImageView[@content-desc='关闭按钮']").click() 25 | # ctx.when(xpath="//android.widget.TextView[@package='com.eg.android.AlipayGphone']").click() 26 | ctx.start() 27 | time.sleep(3) 28 | 29 | 30 | def check_in_task(): 31 | package, _ = get_current_app(d) 32 | if package == "com.taobao.taobao" and (d(className="android.widget.TextView", text="做任务赚元宝").exists or d(className="android.widget.TextView", text="红包签到")): 33 | return True 34 | return False 35 | 36 | 37 | def operate_task(): 38 | check_count = 3 39 | while check_count >= 0: 40 | if not check_in_task(): 41 | break 42 | print(f"检查次数:{check_count}当前在任务页面,没有执行任务。。。") 43 | check_count -= 1 44 | if check_count <= 0: 45 | return 46 | time.sleep(2) 47 | start_time = time.time() 48 | while True: 49 | if time.time() - start_time > 18: 50 | break 51 | if not in_other_app: 52 | d.swipe_ext(Direction.FORWARD) 53 | time.sleep(3) 54 | d.swipe_ext(Direction.BACKWARD) 55 | time.sleep(3) 56 | try_count = 0 57 | while True: 58 | if check_in_task(): 59 | print("当前是任务列表画面,不能继续返回") 60 | # d.swipe_ext(Direction.FORWARD) 61 | break 62 | else: 63 | d.press("back") 64 | time.sleep(0.2) 65 | try_count += 1 66 | if try_count > 10: 67 | break 68 | check_error_page() 69 | 70 | 71 | def check_error_page(): 72 | while True: 73 | time.sleep(3) 74 | if check_in_task(): 75 | break 76 | package, activity = get_current_app(d) 77 | if package != "com.taobao.taobao": 78 | d.app_start("com.taobao.taobao", stop=False) 79 | else: 80 | if activity == "com.taobao.tao.welcome.Welcome": 81 | find_coin_btn() 82 | else: 83 | d.press("back") 84 | 85 | 86 | def find_coin_btn(): 87 | sign_btn = d(className="android.view.View", description="红包签到") 88 | if sign_btn.exists: 89 | print("点击红包签到按钮") 90 | d.double_click(sign_btn[0].center()[0], sign_btn[0].center()[1]) 91 | time.sleep(10) 92 | else: 93 | raise Exception("没有找到红包签到按钮") 94 | 95 | 96 | def find_earn_btn(stop=True): 97 | earn_btn = d(className="android.widget.Button", textContains="赚元宝") 98 | if earn_btn.exists: 99 | earn_btn.click() 100 | time.sleep(5) 101 | else: 102 | continue_btn = d(className="android.widget.Button", text="继续领钱") 103 | if continue_btn.exists: 104 | d.click(continue_btn[0].bounds()[0] - 50, continue_btn[0].center()[1]) 105 | time.sleep(5) 106 | else: 107 | if stop: 108 | raise Exception("没有找到金币任务按钮") 109 | 110 | 111 | ctx.wait_stable() 112 | close_btn = d(className="android.widget.ImageView", description="关闭按钮") 113 | if close_btn and close_btn.exists: 114 | close_btn.click() 115 | time.sleep(3) 116 | find_coin_btn() 117 | earn_btn = d(className="android.widget.Button", textMatches="立即签到") 118 | if earn_btn.exists: 119 | earn_btn.click() 120 | time.sleep(10) 121 | to_btn = d(className="android.widget.TextView", textMatches="立即领.*元宝") 122 | if to_btn.exists: 123 | to_btn.click() 124 | start_time = time.time() 125 | while True: 126 | if time.time() - start_time > 35: 127 | break 128 | d.swipe_ext(Direction.FORWARD) 129 | time.sleep(3) 130 | d.swipe_ext(Direction.BACKWARD) 131 | time.sleep(3) 132 | d.press("back") 133 | get_btn = d(className="android.widget.Button", textMatches="点击领取") 134 | if get_btn.exists: 135 | get_btn.click() 136 | time.sleep(5) 137 | find_earn_btn() 138 | print("点击开始做任务") 139 | finish_count = 0 140 | while True: 141 | try: 142 | in_other_app = False 143 | time.sleep(4) 144 | find_earn_btn(False) 145 | draw_down_btn = d(className="android.widget.Button", text="立即领取") 146 | if draw_down_btn.exists: 147 | draw_down_btn.click() 148 | time.sleep(2) 149 | print("开始查找按钮。。。") 150 | get_btn = d(className="android.widget.Button", text="领取奖励") 151 | if get_btn.exists: 152 | get_btn.click() 153 | print("点击领取奖励") 154 | time.sleep(2) 155 | continue 156 | de_btn = d(className="android.widget.Button", text="点击得") 157 | if de_btn.exists: 158 | de_btn.click() 159 | print("点击点击得") 160 | time.sleep(4) 161 | continue 162 | to_btn = d(className="android.widget.Button", textMatches="去完成|去逛逛|去浏览|逛一逛|立即领|去领取|去看看|搜一下|玩一把|捐一笔|逛一下") 163 | if to_btn.exists: 164 | need_click_view = None 165 | need_click_index = 0 166 | task_name = None 167 | for index, view in enumerate(to_btn): 168 | text_div = view.sibling(className="android.view.View", instance=0).child(className="android.widget.TextView", instance=0) 169 | if text_div.exists: 170 | task_name = text_div.get_text() 171 | if check_chars_exist(task_name): 172 | if view not in unclick_btn: 173 | unclick_btn.append(view) 174 | continue 175 | if task_name in have_clicked: 176 | if have_clicked[task_name] >= 2: 177 | continue 178 | need_click_index = index 179 | need_click_view = view 180 | break 181 | if need_click_view: 182 | print("点击按钮", task_name) 183 | if have_clicked.get(task_name) is None: 184 | have_clicked[task_name] = 1 185 | else: 186 | have_clicked[task_name] += 1 187 | if check_chars_exist(task_name, other_app): 188 | in_other_app = True 189 | need_click_view.click() 190 | time.sleep(3.5) 191 | if "微博" in task_name: 192 | time.sleep(8) 193 | else: 194 | search_view = d(className="android.view.View", text="搜索有福利") 195 | search_edit = d(resourceId="com.taobao.taobao:id/searchEdit") 196 | search_btn = d(resourceId="com.taobao.taobao:id/searchbtn") 197 | if search_view.exists: 198 | d(className="android.widget.EditText", instance=0).send_keys("笔记本电脑") 199 | d(className="android.widget.Button", text="搜索").click() 200 | time.sleep(2) 201 | elif search_edit.exists and search_btn.exists: 202 | search_edit.send_keys("笔记本电脑") 203 | search_btn.click() 204 | time.sleep(2) 205 | operate_task() 206 | else: 207 | error_count += 1 208 | print("未找到可点击按钮", error_count) 209 | if error_count >= 2: 210 | break 211 | except Exception as e: 212 | print(e) 213 | continue 214 | ctx.close() 215 | print(f"共自动化完成{finish_count}个任务") 216 | d.shell("settings put system accelerometer_rotation 0") 217 | print("关闭手机自动旋转") 218 | time2 = time.time() 219 | minutes, seconds = divmod(int(time2 - time1), 60) # 同时计算分钟和秒 220 | print(f"共耗时: {minutes} 分钟 {seconds} 秒") 221 | -------------------------------------------------------------------------------- /淘宝618活动.py: -------------------------------------------------------------------------------- 1 | import time 2 | import re 3 | 4 | import uiautomator2 as u2 5 | from uiautomator2 import Direction 6 | from utils import check_chars_exist, other_app, get_current_app, task_loop 7 | 8 | unclick_btn = [] 9 | have_clicked = dict() 10 | is_end = False 11 | in_other_app = False 12 | time1 = time.time() 13 | d = u2.connect() 14 | d.app_start("com.taobao.taobao", stop=True, use_monkey=True) 15 | ctx = d.watch_context() 16 | ctx.when("O1CN012qVB9n1tvZ8ATEQGu_!!6000000005964-2-tps-144-144").click() 17 | ctx.when("O1CN01sORayC1hBVsDQRZoO_!!6000000004239-2-tps-426-128.png_").click() 18 | ctx.when("领取今日奖励").click() 19 | ctx.when("确认").click() 20 | ctx.when("确定").click() 21 | ctx.when("点击刷新").click() 22 | ctx.when("点击重试").click() 23 | ctx.when(xpath="//android.app.Dialog//android.widget.Button[contains(text(), '-tps-')]").click() 24 | ctx.when(xpath="//android.app.Dialog//android.widget.Button[@text='关闭']").click() 25 | ctx.when(xpath="//android.widget.FrameLayout[@resource-id='com.taobao.taobao:id/poplayer_native_state_center_layout_frame_id']//android.widget.ImageView[@content-desc='关闭按钮']").click() 26 | # ctx.when(xpath="//android.widget.TextView[@package='com.eg.android.AlipayGphone']").click() 27 | ctx.start() 28 | time.sleep(3) 29 | 30 | 31 | def check_in_task(): 32 | package, _ = get_current_app(d) 33 | if package == "com.taobao.taobao" and (d(className="android.widget.TextView", text="做任务赚体力").exists or d(className="android.widget.TextView", text="累计任务奖励").exists or d(className="android.widget.TextView", text="赚金币抵钱").exists or d(className="android.widget.TextView", text="今日累计奖励").exists): 34 | return True 35 | return False 36 | 37 | 38 | def operate_task(): 39 | check_count = 3 40 | while check_count >= 0: 41 | if not check_in_task(): 42 | break 43 | print(f"检查次数:{check_count}当前在任务页面,没有执行任务。。。") 44 | check_count -= 1 45 | if check_count <= 0: 46 | return 47 | time.sleep(2) 48 | start_time = time.time() 49 | while True: 50 | if time.time() - start_time > 18: 51 | break 52 | if not in_other_app: 53 | d.swipe_ext(Direction.FORWARD) 54 | time.sleep(3) 55 | d.swipe_ext(Direction.BACKWARD) 56 | time.sleep(3) 57 | try_count = 0 58 | while True: 59 | if check_in_task(): 60 | print("当前是任务列表画面,不能继续返回") 61 | # d.swipe_ext(Direction.FORWARD) 62 | break 63 | else: 64 | d.press("back") 65 | time.sleep(0.2) 66 | try_count += 1 67 | if try_count > 10: 68 | break 69 | check_error_page() 70 | 71 | 72 | def check_error_page(): 73 | while True: 74 | time.sleep(3) 75 | if check_in_task(): 76 | break 77 | package, activity = get_current_app(d) 78 | if package != "com.taobao.taobao": 79 | d.app_start("com.taobao.taobao", stop=False) 80 | else: 81 | if activity == "com.taobao.tao.welcome.Welcome": 82 | find_coin_btn() 83 | jump_btn = d(className="android.widget.Button", textMatches="剩余.*体力") 84 | if jump_btn.exists(timeout=4): 85 | d.click(jump_btn[0].bounds()[2] + 50, jump_btn[0].center()[1]) 86 | time.sleep(5) 87 | else: 88 | d.press("back") 89 | 90 | 91 | def find_coin_btn(): 92 | coin_btn = d(className="android.widget.FrameLayout", description="领淘金币", clickable=True) 93 | if coin_btn.exists: 94 | d.double_click(coin_btn[0].center()[0], coin_btn[0].center()[1]) 95 | time.sleep(5) 96 | else: 97 | d(className="android.view.View", description="搜索栏").click() 98 | d(resourceId="com.taobao.taobao:id/searchEdit").send_keys("淘金币") 99 | time.sleep(3) 100 | d(className="android.view.View", descriptionContains="淘金币").click() 101 | time.sleep(5) 102 | 103 | 104 | ctx.wait_stable() 105 | close_btn = d(className="android.widget.ImageView", description="关闭按钮") 106 | if close_btn.exists: 107 | close_btn.click() 108 | time.sleep(3) 109 | find_coin_btn() 110 | 111 | 112 | def do_task(): 113 | error_count = 0 114 | global in_other_app 115 | while True: 116 | try: 117 | in_other_app = False 118 | time.sleep(4) 119 | draw_down_btn = d(className="android.widget.Button", text="立即领取") 120 | if draw_down_btn.exists: 121 | draw_down_btn.click() 122 | time.sleep(2) 123 | print("开始查找按钮。。。") 124 | get_btn = d(className="android.widget.Button", text="领取奖励") 125 | if get_btn.exists: 126 | get_btn.click() 127 | print("点击领取奖励") 128 | time.sleep(2) 129 | continue 130 | de_btn = d(className="android.widget.Button", text="点击得") 131 | if de_btn.exists: 132 | de_btn.click() 133 | print("点击点击得") 134 | time.sleep(4) 135 | continue 136 | to_btn = d(className="android.widget.Button", textMatches="去完成|去逛逛|去浏览|逛一逛|立即领|去领取|去看看|搜一下|玩一把|捐一笔|逛一下") 137 | if to_btn.exists: 138 | need_click_view = None 139 | need_click_index = 0 140 | task_name = None 141 | for index, view in enumerate(to_btn): 142 | text_div = view.sibling(className="android.view.View", instance=0).child(className="android.widget.TextView", instance=0) 143 | if text_div.exists: 144 | task_name = text_div.get_text() 145 | if check_chars_exist(task_name): 146 | if view not in unclick_btn: 147 | unclick_btn.append(view) 148 | continue 149 | if task_name in have_clicked: 150 | if have_clicked[task_name] >= 2: 151 | continue 152 | need_click_index = index 153 | need_click_view = view 154 | break 155 | if need_click_view: 156 | print("点击按钮", task_name) 157 | if have_clicked.get(task_name) is None: 158 | have_clicked[task_name] = 1 159 | else: 160 | have_clicked[task_name] += 1 161 | if check_chars_exist(task_name, other_app): 162 | in_other_app = True 163 | need_click_view.click() 164 | time.sleep(3.5) 165 | task_loop(d, check_in_task) 166 | else: 167 | error_count += 1 168 | print("未找到可点击按钮", error_count) 169 | if error_count >= 2: 170 | break 171 | except Exception as e: 172 | print(e) 173 | continue 174 | 175 | 176 | finish_count = 0 177 | for i in range(2): 178 | jump_btn = d(className="android.widget.Button", textMatches="剩余.*体力") 179 | if jump_btn.exists: 180 | if i == 0: 181 | d.click(jump_btn[0].bounds()[2] + 50, jump_btn[0].center()[1]) 182 | print("点击开始赚体力") 183 | time.sleep(5) 184 | else: 185 | d.click(jump_btn[0].bounds()[0] - 50, jump_btn[0].center()[1]) 186 | print("点击开始赚金币") 187 | time.sleep(5) 188 | do_task() 189 | d.click(400, 250) 190 | time.sleep(3) 191 | else: 192 | image_wrap = d(className="android.widget.Image", resourceId="eva-canvas") 193 | if image_wrap.exists: 194 | if i == 0: 195 | d.click(image_wrap[0].bounds()[2] - 100, image_wrap[0].bounds()[3] - 50) 196 | print("点击开始赚体力") 197 | time.sleep(5) 198 | else: 199 | d.click(image_wrap[0].bounds()[0] + 100, image_wrap[0].bounds()[3] - 50) 200 | print("点击开始赚金币") 201 | time.sleep(5) 202 | do_task() 203 | print("点击关闭任务列表") 204 | d.click(400, 250) 205 | time.sleep(3) 206 | print("开始点击跳一跳按钮") 207 | while True: 208 | if check_in_task(): 209 | break 210 | jump_btn = d(className="android.widget.Button", textMatches="剩余.*体力") 211 | image_wrap = d(className="android.widget.Image", resourceId="eva-canvas") 212 | if jump_btn.exists: 213 | count_text = jump_btn.get_text() 214 | print(count_text) 215 | jump_count = int(re.findall(r"\d+", count_text)[0]) 216 | if jump_count < 10: 217 | break 218 | jump_btn.click() 219 | print("点击跳一跳按钮") 220 | time.sleep(3) 221 | elif image_wrap.exists: 222 | d.click(image_wrap[0].center()[0], image_wrap[0].bounds()[3] - 50) 223 | print("根据坐标点击跳一跳") 224 | time.sleep(3) 225 | else: 226 | break 227 | ctx.close() 228 | d.shell("settings put system accelerometer_rotation 0") 229 | print("关闭手机自动旋转") 230 | time2 = time.time() 231 | minutes, seconds = divmod(int(time2 - time1), 60) # 同时计算分钟和秒 232 | print(f"共耗时: {minutes} 分钟 {seconds} 秒") 233 | -------------------------------------------------------------------------------- /2025淘宝双11.py: -------------------------------------------------------------------------------- 1 | import time 2 | import random 3 | import re 4 | 5 | import uiautomator2 as u2 6 | from uiautomator2 import Direction 7 | from utils import check_chars_exist, other_app, get_current_app, select_device 8 | 9 | selected_device = select_device() 10 | d = u2.connect(selected_device) 11 | print(f"已成功连接设备:{selected_device}") 12 | 13 | d.app_start("com.taobao.taobao", stop=True, use_monkey=True) 14 | screen_width = d.info['displayWidth'] 15 | screen_height = d.info['displayHeight'] 16 | time.sleep(5) 17 | in_search = False 18 | in_other_app = False 19 | have_clicked = {} 20 | 21 | ctx = d.watch_context() 22 | # ctx.when("O1CN012qVB9n1tvZ8ATEQGu_!!6000000005964-2-tps-144-144").click() 23 | # ctx.when("O1CN01TkBa3v1zgLfbNmfp7_!!6000000006743-2-tps-72-72").click() 24 | ctx.when("点击刷新").click() 25 | # ctx.when(xpath="//android.app.Dialog//android.widget.Button[@text='关闭']").click() 26 | # ctx.when(xpath="//android.widget.TextView[@package='com.eg.android.AlipayGphone']").click() 27 | ctx.when(xpath="//android.widget.FrameLayout[@resource-id='com.taobao.taobao:id/poplayer_native_state_center_layout_frame_id']/android.widget.ImageView").click() 28 | ctx.start() 29 | 30 | 31 | def close_all_dialog(): 32 | btn1 = d(className="android.widget.TextView", text="去使用") 33 | if btn1.exists: 34 | btn1.right(className="android.widget.ImageView").click() 35 | time.sleep(2) 36 | share_view = d(className="android.view.View", textMatches=r"分享给好友立得体力|去抢频道额外优惠") 37 | if share_view.exists: 38 | print("存在分享给好友立得体力弹框,关闭它") 39 | close_btn1 = d.xpath('//android.view.View[@text="分享给好友立得体力" or @text="去抢频道额外优惠"]/preceding-sibling::android.view.View[3]') 40 | if close_btn1.exists: 41 | print("关闭按钮存在,关闭它") 42 | close_btn1.click() 43 | time.sleep(3) 44 | dialog_view2 = d(className="android.view.View", text="去赚体力") 45 | if dialog_view2.exists: 46 | print("存在去赚体力弹框,关闭它") 47 | close_btn1 = d.xpath('//android.view.View[@text="去赚体力"]/preceding-sibling::android.view.View[5]') 48 | if close_btn1.exists: 49 | print("关闭按钮存在,关闭它") 50 | close_btn1.click() 51 | time.sleep(3) 52 | dialog_view3 = d(className="android.widget.TextView", text="去下单") 53 | if dialog_view3.exists: 54 | close_btn1 = d(className="android.widget.Image", text="关闭") 55 | if close_btn1.exists: 56 | close_btn1.click() 57 | time.sleep(3) 58 | 59 | 60 | def check_in_task(): 61 | temp_package, temp_activity = get_current_app(d) 62 | if temp_package == "com.taobao.taobao" and temp_activity == "com.taobao.themis.container.app.TMSActivity": 63 | phy_view = d(className="android.widget.TextView", text="做任务赚体力") 64 | if phy_view.exists(timeout=5): 65 | return True 66 | elif temp_package == "com.taobao.taobao" and temp_activity == "com.taobao.tao.welcome.Welcome": 67 | to_11() 68 | return True 69 | return False 70 | 71 | 72 | def to_11(): 73 | while True: 74 | package_name, activity_name = get_current_app(d) 75 | if package_name == "com.taobao.taobao" and activity_name != "com.taobao.tao.welcome.Welcome": 76 | break 77 | coin_btn = d(className="android.view.View", description="领淘金币") 78 | if coin_btn.exists: 79 | coin_btn.click() 80 | else: 81 | raise Exception("没有找到领淘金币按钮") 82 | time.sleep(4) 83 | time.sleep(10) 84 | print("进入领淘金币页面") 85 | close_all_dialog() 86 | while True: 87 | physical_btn = d(className="android.widget.Button", text="赚体力") 88 | if physical_btn.exists: 89 | physical_btn.click() 90 | time.sleep(5) 91 | if check_in_task(): 92 | break 93 | 94 | 95 | def operate_task(repeat=False): 96 | start_time = time.time() 97 | cancel_btn = d(resourceId="android:id/button2", text="取消") 98 | if cancel_btn.exists: 99 | cancel_btn.click() 100 | time.sleep(2) 101 | return 102 | while True: 103 | now_time = time.time() 104 | print(f"{int(now_time)}------{int(start_time)}-----{int(now_time - start_time)}") 105 | if now_time - start_time > (25 if repeat else 20): 106 | break 107 | start_x = random.randint(screen_width // 6, screen_width // 2) 108 | start_y = random.randint(screen_height // 2, screen_height - screen_height // 4) 109 | end_x = random.randint(start_x - 100, start_x) 110 | end_y = random.randint(start_y - 800, start_y - 300) 111 | swipe_time = random.uniform(0.4, 1) if end_y - start_y > 500 else random.uniform(0.2, 0.5) 112 | print("模拟滑动", start_x, start_y, end_x, end_y, swipe_time) 113 | d.swipe(start_x, start_y, end_x, end_y, swipe_time) 114 | time.sleep(random.uniform(1, 2.5)) 115 | print("开始返回界面") 116 | while True: 117 | if check_in_task(): 118 | print("当前是任务列表画面,不能继续返回") 119 | break 120 | else: 121 | temp_package, temp_activity = get_current_app(d) 122 | if temp_package is None or temp_activity is None: 123 | continue 124 | print(f"{temp_package}--{temp_activity}") 125 | if "com.taobao.taobao" not in temp_package: 126 | print("回到淘宝APP") 127 | d.app_start("com.taobao.taobao", stop=False) 128 | time.sleep(2) 129 | else: 130 | print("点击后退") 131 | d.press("back") 132 | time.sleep(0.5) 133 | 134 | 135 | to_11() 136 | finish_count = 0 137 | time1 = time.time() 138 | while True: 139 | try: 140 | print("开始查找任务。。。") 141 | if not check_in_task(): 142 | physical_btn = d(className="android.widget.Button", text="赚体力") 143 | if physical_btn.exists: 144 | physical_btn.click() 145 | time.sleep(5) 146 | get_btn = d(className="android.widget.Button", text="立即领取") 147 | if get_btn.exists: 148 | get_btn.click() 149 | time.sleep(3) 150 | to_btn = d(className="android.widget.Button", text="去完成") 151 | if to_btn.exists: 152 | need_click_view = None 153 | need_click_index = 0 154 | task_name = None 155 | for index, view in enumerate(to_btn): 156 | text_div = view.sibling(className="android.view.View", instance=0).child(className="android.widget.TextView", instance=0) 157 | if text_div.exists: 158 | if check_chars_exist(text_div.get_text()): 159 | continue 160 | task_name = text_div.get_text() 161 | if task_name in have_clicked and have_clicked[task_name] > 2: 162 | continue 163 | need_click_index = index 164 | need_click_view = view 165 | break 166 | if need_click_view: 167 | print("点击按钮", task_name) 168 | if task_name not in have_clicked: 169 | have_clicked[task_name] = 1 170 | else: 171 | have_clicked[task_name] += 1 172 | # need_click_view.click() 173 | d.click(random.randint(need_click_view.bounds()[0] + 10, need_click_view.bounds()[2] - 10), random.randint(need_click_view.bounds()[1] + 10, need_click_view.bounds()[3] - 10)) 174 | time.sleep(4) 175 | open_btn = d(className="android.widget.Button", resourceIdMatches=r"android:id/.*", textMatches="打开|允许") 176 | if open_btn.exists: 177 | open_btn.click() 178 | time.sleep(4) 179 | search_view = d(className="android.view.View", text="搜索有福利") 180 | if search_view.exists: 181 | d(className="android.widget.EditText", instance=0).send_keys("笔记本电脑") 182 | d(className="android.widget.Button", text="搜索").click() 183 | in_search = True 184 | time.sleep(4) 185 | operate_task(have_clicked[task_name]>1) 186 | finish_count += 1 187 | else: 188 | break 189 | time.sleep(5) 190 | except Exception as e: 191 | print("出现异常,继续下一轮", str(e)) 192 | print(f"共自动化完成{finish_count}个任务") 193 | temp_btn = d(className="android.widget.TextView", text="做任务赚体力") 194 | if temp_btn.exists: 195 | print("点击缩回弹框") 196 | try: 197 | close_btn = temp_btn.right(className="android.widget.Button") 198 | if close_btn.exists: 199 | close_btn.click() 200 | except Exception: 201 | d.shell("input tap 500 300") 202 | time.sleep(4) 203 | while True: 204 | print("开始跳一跳。。。") 205 | close_all_dialog() 206 | dump_btn = d(className="android.widget.Button", textContains="跳一跳拿钱") 207 | if dump_btn.exists: 208 | dump_text = dump_btn.get_text() 209 | match = re.search(r'剩余 (\d+) 体力', dump_text) 210 | if match: 211 | phy_num = int(match.group(1)) 212 | if phy_num < 10: 213 | break 214 | print(f"当前剩余体力:{phy_num}") 215 | if phy_num < 50: 216 | dump_btn.click() 217 | else: 218 | # d.shell(f"input touchscreen swipe {dump_btn.center()[0]} {dump_btn.center()[1]} {dump_btn.center()[0]} {dump_btn.center()[1]} 5000") 219 | dump_btn.long_click(duration=5) 220 | time.sleep(7) 221 | else: 222 | break 223 | else: 224 | break 225 | 226 | d.watcher.remove() 227 | d.shell("settings put system accelerometer_rotation 0") 228 | print("关闭手机自动旋转") 229 | time2 = time.time() 230 | minutes, seconds = divmod(int(time2 - time1), 60) # 同时计算分钟和秒 231 | print(f"共耗时: {minutes} 分钟 {seconds} 秒") 232 | -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | import time 2 | import random 3 | import re 4 | import cv2 5 | import numpy as np 6 | import ddddocr 7 | import subprocess 8 | 9 | TB_APP = "com.taobao.taobao" 10 | ALIPAY_APP = "com.eg.android.AlipayGphone" 11 | FISH_APP = "com.taobao.idlefish" 12 | 13 | 14 | def check_chars_exist(text, chars=None): 15 | if chars is None: 16 | chars = ["拉好友", "抢红包", "搜索兴趣商品下单", "买精选商品", "全场3元3件", "固定入口", "农场小游戏", "砸蛋", 17 | "大众点评", "蚂蚁新村", "消消乐", "3元抢3件包邮到家", "拍一拍", "1元抢爆款好货", "拉1人助力", 18 | "玩消消乐", "下单即得", "添加签到神器", "下单得肥料", "88VIP", "邀请好友", "好货限时直降", "连连消", 19 | "下单即得", "拍立淘", "玩任意游戏", "首页回访", "百亿外卖", "玩趣味游戏得大额体力", "天猫积分换体力", 20 | "头条刷热点", "一淘签到", "每拉", "闪购拿大额补贴", "开心消消乐过1关", "通关", "购买商品", "去闪购领红包点外卖"] 21 | for char in chars: 22 | if char in text: 23 | return True 24 | return False 25 | 26 | 27 | def get_current_app(d): 28 | info = d.shell("dumpsys window | grep mCurrentFocus").output 29 | match = re.search(r'mCurrentFocus=Window\{.*? u0 (.*?)/(.*?)\}', info) 30 | if match: 31 | package_name = match.group(1) 32 | activity_name = match.group(2) 33 | return package_name, activity_name 34 | return None, None 35 | 36 | 37 | other_app = ["蚂蚁森林", "农场", "百度", "支付宝", "芝麻信用", "蚂蚁庄园", "闲鱼", "神奇海洋", "淘宝特价版", "点淘", 38 | "饿了么", "微博", "直播", "领肥料礼包", "福气提现金", "看小说", "菜鸟", "斗地主", "领肥料礼包"] 39 | 40 | 41 | def fish_not_click(text, chars=None): 42 | if chars is None: 43 | chars = ["发布一件新宝贝", "买到或卖出", "中国移动", "视频", "下单", "点淘", "一淘", "收藏", "购买"] 44 | for char in chars: 45 | if char in text: 46 | return True 47 | return False 48 | 49 | 50 | def find_button(image, btn_path, region=None): 51 | template = cv2.imread(btn_path) 52 | # 如果指定了区域,裁剪图像 53 | if region is not None: 54 | x, y, w_region, h_region = region 55 | image = image[y:y + h_region, x:x + w_region] 56 | # 转换为灰度图像 57 | screenshot_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 58 | template_gray = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY) 59 | # 获取模板图像的宽度和高度 60 | w, h = template_gray.shape[::-1] 61 | # 使用模板匹配 62 | res = cv2.matchTemplate(screenshot_gray, template_gray, cv2.TM_CCOEFF_NORMED) 63 | threshold = 0.8 64 | loc = np.where(res >= threshold) 65 | for pt in zip(*loc[::-1]): 66 | return pt 67 | return None 68 | 69 | 70 | def find_text_position(image, text): 71 | ocr = ddddocr.DdddOcr(show_ad=False) 72 | ocr_result = ocr.classification(image) 73 | # 将 OCR 结果按行解析 74 | lines = ocr_result.split('\n') 75 | # 遍历每一行,查找目标文本的位置 76 | for line in lines: 77 | if text in line: 78 | # 获取文本的位置 79 | start_index = line.find(text) 80 | end_index = start_index + len(text) 81 | return start_index, end_index 82 | return None 83 | 84 | 85 | # 判断一个字符是否为中文字符 86 | def is_chinese(char): 87 | return '\u4e00' <= char <= '\u9fff' 88 | 89 | 90 | def majority_chinese(text): 91 | if not text: 92 | return False 93 | chinese_count = sum(1 for char in text if is_chinese(char)) 94 | return chinese_count > len(text) / 2 95 | 96 | 97 | search_keys = ["华硕a豆air", "机械革命星耀14", "ipadmini7", "iphone16", "红米note13", "macbookairm4", "华硕灵耀14", 98 | "微星星影15"] 99 | 100 | 101 | def task_loop(d, func, origin_app=TB_APP, is_fish=False): 102 | history_lst = d.xpath( 103 | '(//android.widget.TextView[@text="历史搜索"]/following-sibling::android.widget.ListView)/android.view.View[1]') 104 | if history_lst.exists: 105 | print("查找到搜索关键字", history_lst) 106 | history_lst.click() 107 | time.sleep(2) 108 | else: 109 | search_view = d(className="android.view.View", text="搜索有福利") 110 | if search_view.exists: 111 | search_edit = d.xpath("//android.widget.EditText") 112 | if search_edit.exists: 113 | search_edit.set_text(random.choice(search_keys)) 114 | search_btn = d(className="android.widget.Button", text="搜索") 115 | if search_btn.exists: 116 | search_btn.click() 117 | time.sleep(2) 118 | screen_width, screen_height = d.window_size() 119 | package_name, _ = get_current_app(d) 120 | check_count = 3 121 | while check_count >= 0: 122 | if not func(): 123 | break 124 | print(f"检查次数:{check_count}当前在任务页面,没有执行任务。。。") 125 | check_count -= 1 126 | if check_count <= 0: 127 | return 128 | time.sleep(2) 129 | start_time = time.time() 130 | while True: 131 | try: 132 | bt_open = d(resourceId="android:id/button1", text="浏览器打开") 133 | if bt_open.exists: 134 | bt_close = d(resourceId="android:id/button2", text="取消") 135 | if bt_close.exists: 136 | bt_close.click() 137 | time.sleep(2) 138 | break 139 | if time.time() - start_time > 22: 140 | break 141 | if package_name == origin_app: 142 | if package_name == ALIPAY_APP: 143 | screen_image = d.screenshot(format='opencv') 144 | pt1 = find_button(screen_image, "./img/alipay_get.png") 145 | if pt1: 146 | print("检测到立即领取的弹框,点击立即领取") 147 | d.click(int(pt1[0]) + 50, int(pt1[1]) + 20) 148 | time.sleep(1) 149 | if is_fish: 150 | print("开始查找闲鱼商品") 151 | time.sleep(4) 152 | commodity_view1 = d.xpath("//android.widget.ListView/android.view.View[1]") 153 | if commodity_view1.exists: 154 | commodity_view1.click() 155 | time.sleep(18) 156 | break 157 | commodity_view2 = d(className="android.view.View", resourceId="feedsContainer") 158 | if commodity_view2.exists: 159 | d.click(100, commodity_view2.center()[1]) 160 | time.sleep(18) 161 | break 162 | else: 163 | start_x = random.randint(screen_width // 6, screen_width // 2) 164 | start_y = random.randint(screen_height // 2, screen_height - screen_width // 4) 165 | end_x = random.randint(start_x - 100, start_x) 166 | end_y = random.randint(200, start_y - 300) 167 | swipe_time = random.uniform(0.4, 1) if end_y - start_y > 500 else random.uniform(0.2, 0.5) 168 | print("模拟滑动", start_x, start_y, end_x, end_y, swipe_time) 169 | d.swipe(start_x, start_y, end_x, end_y, swipe_time) 170 | time.sleep(random.uniform(1, 2.5)) 171 | else: 172 | time.sleep(5) 173 | except Exception as e: 174 | time.sleep(5) 175 | print("开始返回任务页面") 176 | while True: 177 | temp_package, temp_activity = get_current_app(d) 178 | if temp_package is None or temp_activity is None: 179 | continue 180 | print(f"{temp_package}--{temp_activity}") 181 | if origin_app not in temp_package: 182 | print("回到淘宝APP") 183 | d.app_start(origin_app, stop=False) 184 | time.sleep(3) 185 | else: 186 | if func(): 187 | print("当前是任务列表画面,不能继续返回") 188 | break 189 | else: 190 | close_btn1 = d.xpath("//android.widget.FrameLayout[@resource-id='com.alipay.multiplatform.phone.xriver_integration:id/frameLayout_rightButton1']/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]") 191 | if close_btn1.exists: 192 | print("点击关闭小程序按钮") 193 | close_btn1.click() 194 | time.sleep(1) 195 | continue 196 | # close_btn2 = d.xpath("//android.view.View[@resource-id='root']/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.Image") 197 | # if close_btn2.exists: 198 | # print("后退按钮存在,点击后退按钮") 199 | # close_btn2.click() 200 | # time.sleep(1) 201 | # continue 202 | print("点击后退") 203 | d.press("back") 204 | time.sleep(0.3) 205 | 206 | 207 | def close_xy_dialog(d): 208 | dialog_view1 = d.xpath( 209 | '//android.webkit.WebView[@text="闲鱼币首页"]/android.view.View/android.view.View[2]//android.widget.Image[1]') 210 | if dialog_view1.exists: 211 | dialog_view1.click() 212 | time.sleep(2) 213 | 214 | 215 | def get_connected_devices(): 216 | """通过ADB获取所有连接的安卓设备序列号""" 217 | try: 218 | # 执行adb命令获取设备列表 219 | result = subprocess.run( 220 | ["adb", "devices"], 221 | capture_output=True, 222 | text=True, 223 | check=True 224 | ) 225 | 226 | # 解析输出,提取设备序列号 227 | output = result.stdout 228 | devices = [] 229 | for line in output.splitlines(): 230 | # 跳过标题行和空行 231 | if line.strip() == "" or line.startswith("List of devices attached"): 232 | continue 233 | match = re.match(r"^([^\s]+)\s+device$", line) 234 | if match: 235 | devices.append(match.group(1)) 236 | return devices 237 | except subprocess.CalledProcessError: 238 | print("执行ADB命令失败,请确保ADB已正确安装并添加到环境变量") 239 | return [] 240 | except FileNotFoundError: 241 | print("未找到ADB命令,请确保ADB已正确安装并添加到环境变量") 242 | return [] 243 | 244 | 245 | # 从已连接的设备中,返回用户选中的设备序列号 246 | def select_device(): 247 | # 获取所有连接的设备 248 | devices = get_connected_devices() 249 | 250 | if not devices: 251 | raise Exception("未检测到任何连接的安卓设备") 252 | 253 | # 根据设备数量进行处理 254 | if len(devices) == 1: 255 | # 只有一个设备,直接返回 256 | return devices[0] 257 | else: 258 | # 多个设备,让用户选择 259 | print("当前连接多个设备,请输入要执行的设备序号:") 260 | for i, device in enumerate(devices, 1): 261 | print(f" {i}: {device}") 262 | 263 | # 获取用户输入并验证 264 | while True: 265 | try: 266 | choice = input("请输入设备序号:") 267 | index = int(choice) - 1 # 转换为列表索引 268 | 269 | if 0 <= index < len(devices): 270 | # 选中的设备 271 | return devices[index] 272 | else: 273 | print(f"输入错误,请重新输入序号(1-{len(devices)})") 274 | except ValueError: 275 | print(f"输入错误,请重新输入序号(1-{len(devices)})") 276 | 277 | 278 | def check_verify(d): 279 | verify_view = d(className="android.webkit.WebView", text="验证码拦截") 280 | if verify_view.exists: 281 | while True: 282 | print("存在验证码的情况") 283 | d.shell("input swipe 150 1700 1180 1700 500") 284 | time.sleep(3) 285 | verify_view = d(className="android.webkit.WebView", text="验证码拦截") 286 | if verify_view.exists: 287 | d.click(500, 1700) 288 | time.sleep(3) 289 | else: 290 | print("验证码滑动成功") 291 | break 292 | 293 | 294 | # pt = find_button(cv2.imread("screenshot.png"), "img/alipay_get.png") 295 | # print(pt) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /闲鱼任务.py: -------------------------------------------------------------------------------- 1 | import time 2 | import re 3 | 4 | import ddddocr 5 | import uiautomator2 as u2 6 | 7 | from utils import get_current_app, find_button, close_xy_dialog, task_loop, FISH_APP 8 | 9 | d = u2.connect() 10 | # origin_timeout = d.shell("settings get system screen_off_timeout").output 11 | # d.shell("settings put system screen_off_timeout 86400000") 12 | d.app_start("com.taobao.idlefish", stop=True, use_monkey=True) 13 | screen_width, screen_height = d.window_size() 14 | ctx = d.watch_context() 15 | ctx.when("暂不升级").click() 16 | ctx.when("放弃").click() 17 | ctx.when("确定").click() 18 | ctx.start() 19 | have_clicked = dict() 20 | error_count = 0 21 | ocr = ddddocr.DdddOcr(show_ad=False) 22 | finish_count = 0 23 | xy_task_name = ["领至高20元外卖红包", "浏览指定频道好物", "搜一搜推荐商品", "去浏览全新好物", "浏览推荐的国补商品", "去支付宝领积分", "去淘宝签到领红包", "去蚂蚁庄园逛一逛", "去逛一逛芭芭农场", "去支付宝农场领水果", "去蚂蚁森林逛一逛", "去百度逛一逛", "去饿了么果园领水果", "褥羊毛赚话费", "去天猫拿红包", "逛一逛淘宝人生", "去淘特领好礼", "上夸克天天领现金", "去淘金币赢20亿", "快手极速版"] 24 | 25 | 26 | def check_in_xy(): 27 | home_view = d(className="android.webkit.WebView", text="闲鱼币首页") 28 | task_dialog = d(resourceId="taskWrap", className="android.view.View") 29 | if home_view.exists and task_dialog.exists: 30 | print("任务弹框存在") 31 | return True 32 | return False 33 | 34 | 35 | def to_task(): 36 | while True: 37 | sign_btn1 = d(resourceId="com.taobao.idlefish:id/icon_entry_lottie", className="android.widget.ImageView", clickable=True) 38 | sign_btn2 = d(className="android.widget.ImageView", resourceId="com.taobao.idlefish:id/icon_entry") 39 | print(f"查找签到按钮,存在:{sign_btn1.exists}, {sign_btn2.exists}") 40 | if sign_btn1.exists: 41 | d.click(sign_btn1.center()[0], sign_btn1.center()[1]) 42 | time.sleep(2) 43 | elif sign_btn2.exists: 44 | d.click(sign_btn2.center()[0], sign_btn2.center()[1]) 45 | time.sleep(2) 46 | if d(className="android.webkit.WebView", text="闲鱼币首页").exists: 47 | print("已经进入闲鱼页面") 48 | break 49 | time.sleep(1) 50 | time.sleep(10) 51 | close_xy_dialog(d) 52 | 53 | 54 | def click_earn(): 55 | while True: 56 | print("开始查找去赚钱按钮") 57 | if d(className="android.view.View", resourceId="taskWrap").exists: 58 | print("任务弹框存在") 59 | break 60 | throw_btn1 = d(className="android.view.View", resourceId="mapDiceBtn") 61 | if throw_btn1.exists: 62 | print("点击任务按钮") 63 | d.click(throw_btn1.bounds()[2] + 100, throw_btn1.center()[1] + 30) 64 | time.sleep(2) 65 | 66 | 67 | def back_to_task(): 68 | print("开始返回到闲鱼币首页。") 69 | try_count = 0 70 | while True: 71 | if check_in_xy(): 72 | break 73 | else: 74 | package_name, activity_name = get_current_app(d) 75 | if package_name != "com.taobao.idlefish": 76 | d.app_start("com.taobao.idlefish", stop=False) 77 | time.sleep(2) 78 | # bt_refresh = d(resourceId="com.taobao.idlefish:id/state_action", text="刷新") 79 | # if bt_refresh.exists: 80 | # print("点击刷新按钮") 81 | # bt_refresh.click() 82 | # time.sleep(2) 83 | else: 84 | if activity_name == "com.taobao.idlefish.maincontainer.activity.MainActivity": 85 | to_task() 86 | click_earn() 87 | break 88 | else: 89 | back_btn = d.xpath('//android.view.View[@resource-id="root"]/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.Image') 90 | if back_btn.exists and try_count % 4 == 0: 91 | print("点击后退按钮") 92 | back_btn.click() 93 | time.sleep(0.5) 94 | else: 95 | d.press("back") 96 | time.sleep(0.1) 97 | try_count += 1 98 | 99 | 100 | def operate_task(task): 101 | _, activity = get_current_app(d) 102 | start_time = time.time() 103 | if task == "浏览指定频道好物": 104 | while True: 105 | if time.time() - start_time > 24: 106 | break 107 | d.swipe_ext("up", scale=0.3) 108 | time.sleep(0.5) 109 | d(scrollable=True).fling.vert.toBeginning(max_swipes=1000) 110 | time.sleep(2) 111 | click_earn() 112 | else: 113 | print("普通页面") 114 | search_view = d(className="android.view.View", text="搜索有福利") 115 | search_edit = d(resourceId="com.taobao.taobao:id/searchEdit") 116 | search_btn = d(resourceId="com.taobao.taobao:id/searchbtn") 117 | if search_view.exists and d(className="android.widget.Button", text="搜索").exists: 118 | d(className="android.widget.EditText", instance=0).send_keys("笔记本电脑") 119 | d(className="android.widget.Button", text="搜索").click() 120 | time.sleep(2) 121 | elif search_edit.exists and search_btn.exists: 122 | search_edit.send_keys("笔记本电脑") 123 | search_btn.click() 124 | time.sleep(2) 125 | time.sleep(3) 126 | print("开始上下滑动") 127 | start_time = time.time() 128 | tap_index = 0 129 | while True: 130 | if tap_index % 4 == 0 and tap_index > 0: 131 | d.swipe_ext("down", scale=0.4) 132 | else: 133 | d.swipe_ext("up", scale=0.4) 134 | time.sleep(0.3) 135 | tap_index += 1 136 | if time.time() - start_time > 25: 137 | break 138 | print("滑动完毕,开始退出") 139 | back_to_task() 140 | 141 | 142 | def check_popup(): 143 | draw_btn = d(className="android.widget.TextView", text="开始抽奖") 144 | if draw_btn.exists: 145 | d.click(draw_btn.center()[0], draw_btn.center()[1]) 146 | time.sleep(10) 147 | return 148 | receive_btn3 = d(className="android.widget.TextView", text="领取奖励") 149 | if receive_btn3.exists: 150 | d.click(receive_btn3.center()[0], receive_btn3.center()[1]) 151 | time.sleep(3) 152 | return 153 | know_btn = d(className="android.widget.TextView", text="我知道了") 154 | if know_btn.exists: 155 | d.click(know_btn.center()[0], know_btn.center()[1]) 156 | time.sleep(3) 157 | return 158 | scratch_btn = d(className="android.widget.TextView", text="开始刮奖") 159 | if scratch_btn.exists: 160 | scratch_btn.click() 161 | time.sleep(15) 162 | return 163 | in_btn = d(className="android.widget.TextView", text="收下礼物") 164 | if in_btn.exists: 165 | in_btn.click() 166 | time.sleep(3) 167 | return 168 | continue_btn = d(className="android.widget.TextView", text="继续寻宝") 169 | if continue_btn.exists: 170 | continue_btn.click() 171 | time.sleep(3) 172 | return 173 | throw_btn1 = d(className="android.widget.TextView", text="骰子×1") 174 | if throw_btn1.exists: 175 | throw_btn2 = d.xpath('//android.widget.TextView[@text="骰子×1"]/following-sibling::android.widget.TextView[1]') 176 | if throw_btn2.exists: 177 | throw_btn2.click() 178 | time.sleep(3) 179 | return 180 | screen_image = d.screenshot(format='opencv') 181 | pt1 = find_button(screen_image, "./img/fish_advance.png") 182 | if pt1: 183 | d.click(int(pt1[0]) + 50, int(pt1[1]) + 20) 184 | time.sleep(3) 185 | return 186 | pt2 = find_button(screen_image, "./img/fish_continue.png") 187 | if pt2: 188 | d.click(int(pt2[0]) + 50, int(pt2[1]) + 20) 189 | time.sleep(3) 190 | return 191 | pt3 = find_button(screen_image, "./img/fish_continue2.png") 192 | if pt3: 193 | d.click(int(pt3[0]) + 50, int(pt3[1]) + 20) 194 | time.sleep(3) 195 | return 196 | pt4 = find_button(screen_image, "./img/fish_prize.png") 197 | if pt4: 198 | d.click(int(pt4[0]) + 100, int(pt4[1]) + 80) 199 | time.sleep(3) 200 | return 201 | pt5 = find_button(screen_image, "./img/fish_swing.png") 202 | if pt5: 203 | d.click(int(pt5[0]) + 50, int(pt5[1]) + 50) 204 | time.sleep(10) 205 | return 206 | 207 | 208 | time.sleep(5) 209 | ctx.wait_stable() 210 | to_task() 211 | click_earn() 212 | bottom_pos = screen_height 213 | bottom_navigator = d(className="android.widget.FrameLayout",resourceId="com.android.systemui:id/navigation_bar_frame") 214 | if bottom_navigator.exists: 215 | bottom_pos = bottom_navigator.bounds()[1] 216 | while True: 217 | try: 218 | print("正在查找按钮...") 219 | time.sleep(4) 220 | sign_btn = d(className="android.widget.TextView", text="签到") 221 | if sign_btn.exists: 222 | d.click(sign_btn.center()[0], sign_btn.center()[1]) 223 | time.sleep(4) 224 | receive_btn = d(className="android.widget.TextView", text="领取奖励") 225 | if receive_btn.exists: 226 | receive_btn.click() 227 | print("点击领取奖励") 228 | finish_count += 1 229 | time.sleep(2) 230 | continue 231 | # task_view = d.xpath(f"//android.view.View[@resource-id='taskWrap']/android.view.View[last()]/android.view.View/android.widget.TextView[{' or '.join([f"@text='{text}'" for text in xy_task_name])}]") 232 | condition = " or ".join([f'@text="{text}"' for text in xy_task_name]) 233 | task_view = d.xpath(f'//android.view.View[@resource-id="taskWrap"]/android.view.View[last()]//android.widget.TextView[{condition}]') 234 | if task_view.exists: 235 | task_container = d.xpath('//android.view.View[@resource-id="taskWrap"]/android.view.View[last()]') 236 | top_position = None 237 | if task_container.exists: 238 | top_position = task_container.bounds[1] 239 | task_name = task_view.get_text() 240 | if top_position and task_view.bounds[3] < top_position: 241 | print(f"{task_name}超出范围了。等待后再试") 242 | start_x = screen_width // 6 243 | start_y = screen_height // 2 * 3 244 | end_x = start_x + 50 245 | end_y = start_y - 200 246 | d.swipe(start_x, start_y, end_x, end_y, 1) 247 | time.sleep(4) 248 | continue 249 | if have_clicked.get(task_name) is not None and have_clicked.get(task_name) >= 2: 250 | print(f"{task_name}已重试两次,移除出数组") 251 | xy_task_name.remove(task_name) 252 | continue 253 | print(f"查找任务:{task_name}") 254 | todo_btn = task_view.child("./following-sibling::android.view.View[1]/android.widget.TextView") 255 | if todo_btn.exists: 256 | todo_text = todo_btn.get_text() 257 | if todo_text == "已完成": 258 | break 259 | if todo_text != "去完成": 260 | continue 261 | todo_btn.click() 262 | if have_clicked.get(task_name) is None: 263 | have_clicked[task_name] = 1 264 | else: 265 | have_clicked[task_name] += 1 266 | time.sleep(5) 267 | task_loop(d, check_in_xy, origin_app=FISH_APP, is_fish=True) 268 | else: 269 | break 270 | else: 271 | last_view = d.xpath('//android.view.View[@resource-id="taskWrap"]/android.view.View[last()]/android.view.View/android.widget.TextView[last()]') 272 | if last_view.exists and last_view.get_text() == "已完成": 273 | print("已完成按钮存在,退出循环") 274 | break 275 | else: 276 | if not check_in_xy(): 277 | d(scrollable=True).fling.vert.toBeginning(max_swipes=1000) 278 | click_earn() 279 | else: 280 | d.swipe_ext(u2.Direction.FORWARD) 281 | print("上滑查找下一页") 282 | time.sleep(4) 283 | except Exception as e: 284 | print("报错", e) 285 | continue 286 | print(f"共自动化完成{finish_count}个任务") 287 | d.click(screen_width//2, 250) 288 | click_count = 2 289 | while click_count >= 0: 290 | receive_btn2 = d(className="android.view.View", resourceId="dailyRewardBox") 291 | if receive_btn2.exists: 292 | print("点击领取收益") 293 | receive_btn2.click() 294 | time.sleep(3) 295 | else: 296 | break 297 | click_count -= 1 298 | throw_btn = d(className="android.view.View", resourceId="mapDiceBtn") 299 | while True: 300 | print("开始摇骰子...") 301 | count_btn = throw_btn.child(className="android.widget.TextView", index=0) 302 | if count_btn.exists: 303 | print(f"摇骰子次数:{count_btn.get_text()}") 304 | numbers = re.findall(r'\d+', count_btn.get_text()) 305 | if len(numbers) <= 0: 306 | break 307 | count = int(numbers[0]) 308 | if count > 0: 309 | d.click(throw_btn.center()[0], throw_btn.center()[1]) 310 | time.sleep(5) 311 | check_popup() 312 | else: 313 | break 314 | time.sleep(2) 315 | print("任务完成。。。") 316 | ctx.stop() 317 | --------------------------------------------------------------------------------