├── .gitignore └── xy_main2.py /.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 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /xy_main2.py: -------------------------------------------------------------------------------- 1 | import uiautomator2 as u2 2 | import time 3 | from math import ceil 4 | 5 | class XianYu(): 6 | def save_g(self): 7 | self.d(text=u"确认发布", className="android.view.View").click() 8 | while len(self.d(description=u"发布成功", className="android.view.View")) == 0: 9 | pass 10 | print('({}) >>> 后退'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 11 | self.d.press('back') 12 | while True: 13 | if len(self.d(text=u"签到", className="android.widget.TextView")) == 1: 14 | # 第一种情况:进入了地区界面 15 | print('({}) >>> 后退至商品列表界面'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 16 | self.d.press('back') 17 | break 18 | elif len(self.d(text=u"收藏", className="android.widget.ImageView")) == 1: 19 | # 第二种情况:进入了帖子界面 20 | print('({}) >>> 后退至商品列表界面'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 21 | self.d.press('back') 22 | break 23 | 24 | while len(self.d(description=u"编辑")) == 0: 25 | pass 26 | 27 | print('({}) >>> 后退至主界面'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 28 | self.d.press('back') 29 | self.good += 1 30 | print('({}) >>> 完成第 {} 个商品的编辑'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),self.good)) 31 | # 计时 32 | self.btime = int(time.time()) 33 | self.ctime = self.btime - self.atime 34 | print('({}) [用时 {} 秒]\n'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),self.ctime)) 35 | #延时,避免过快被检测 36 | if self.ctime < 13: 37 | print('({}) * 操作过快,自动休息{}秒 *\n'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), 13-self.ctime)) 38 | time.sleep(13-self.ctime) 39 | 40 | 41 | def get_gm(self): 42 | if self.d(resourceId="com.taobao.idlefish:id/entry_title", text=u"我发布的"): 43 | # 获取发布的商品数量 44 | while len(self.d(resourceId="com.taobao.idlefish:id/entry_sub_title", className="android.widget.TextView", 45 | instance=1)) == 0: 46 | pass 47 | 48 | self.goods = int(self.d(resourceId="com.taobao.idlefish:id/entry_sub_title", className="android.widget.TextView", 49 | instance=1).get_text()) 50 | print('({}) >>> 发布的商品数量:{} '.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),self.goods)) 51 | 52 | def get_g(self): 53 | # 计时 54 | self.atime = int(time.time()) 55 | # 点击'我发布的'按钮 56 | print('({}) >>> 点击[我发布的]'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 57 | self.d(resourceId="com.taobao.idlefish:id/entry_title", text=u"我发布的").click() 58 | 59 | # 检测页面加载情况 60 | while len(self.d(description=u"编辑", className="android.view.View")) == 0: 61 | pass 62 | time.sleep(1) 63 | # 移到最底端 64 | print('({}) >>> 移动到最底端'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 65 | for i in range(0,ceil(self.goods/20)): 66 | # 每一次加载20个商品,滑到目前底端才会加载后20个商品 67 | self.d.swipe(0.5, 0.9, 0.5, 0.065, 0.01) 68 | time.sleep(2.5) 69 | 70 | a = len(self.d(description=u"编辑")) - 1 # 屏幕上有多少个编辑按钮 71 | 72 | if a == 0: 73 | # 点击0号'编辑'按钮(鉴于只有一个商品的情况) 74 | print('({}) >>> 点击[编辑]'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 75 | self.d(description=u"编辑", className="android.view.View").click() 76 | 77 | else: 78 | # 点击a号'编辑'按钮(最后一个'编辑'那妞) 79 | print('({}) >>> 点击[编辑]'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 80 | self.d(description=u"编辑", className="android.view.View", instance=a).click() 81 | 82 | self.save_g() 83 | 84 | def __init__(self): 85 | # 主循环 86 | self.d = u2.connect('3e9caa939804') 87 | print('({}) >>> 开始一轮循环'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 88 | # 解锁 89 | self.d.unlock() 90 | self.d.press('home') 91 | self.state = 0 92 | self.good = 0 93 | xianyu = len(self.d(resourceId="com.miui.home:id/icon_title", text=u"闲鱼", className="android.widget.TextView")) 94 | if xianyu == 0: 95 | time.sleep(1) 96 | self.d.press('home') 97 | xianyu = len( 98 | self.d(resourceId="com.miui.home:id/icon_title", text=u"闲鱼", className="android.widget.TextView")) 99 | if xianyu == 0: 100 | print('\n({}) * 未检测到首页存在闲鱼APP,请将闲鱼APP放置在首页 *\n'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 101 | 102 | print('({}) [首页共有 {} 个咸鱼]'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),xianyu)) 103 | for xy in range(0,xianyu): 104 | # 打开首页咸鱼 105 | print('({}) >>> 打开第 {} 个"闲鱼"APP'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),(xy+1))) 106 | if xy == 0: 107 | self.d(resourceId="com.miui.home:id/icon_title", text=u"闲鱼", className="android.widget.TextView").click() 108 | else: 109 | self.d(resourceId="com.miui.home:id/icon_title", text=u"闲鱼",className="android.widget.TextView", 110 | instance=xy).click() 111 | 112 | self.d(resourceId="com.taobao.idlefish:id/tab_title", text=u"我的", className="android.widget.TextView").click() 113 | 114 | # 获取商品数量 115 | self.get_gm() 116 | 117 | # 循环编辑商品 118 | while self.good != self.goods: 119 | self.get_g() 120 | 121 | # 执行完毕 122 | self.good = 0 123 | self.d.press('back') 124 | self.d.press('home') 125 | 126 | print('({}) >>> 全部完成'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 127 | 128 | if __name__ == '__main__': 129 | XianYu() --------------------------------------------------------------------------------