{"id":13843306,"url":"https://github.com/Meteorix/airtest-douyin","last_synced_at":"2025-07-11T18:31:33.227Z","repository":{"id":80183189,"uuid":"169246637","full_name":"Meteorix/airtest-douyin","owner":"Meteorix","description":null,"archived":false,"fork":false,"pushed_at":"2019-02-05T15:59:56.000Z","size":1111,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-05T17:36:53.208Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Meteorix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-02-05T13:36:27.000Z","updated_at":"2023-10-05T14:46:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"e9215c32-7884-4b55-ab9c-1af6f0a798bd","html_url":"https://github.com/Meteorix/airtest-douyin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meteorix%2Fairtest-douyin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meteorix%2Fairtest-douyin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meteorix%2Fairtest-douyin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meteorix%2Fairtest-douyin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Meteorix","download_url":"https://codeload.github.com/Meteorix/airtest-douyin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225745563,"owners_count":17517670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T17:01:59.109Z","updated_at":"2024-11-21T14:31:02.419Z","avatar_url":"https://github.com/Meteorix.png","language":"Python","funding_links":[],"categories":["Python","Python (1887)"],"sub_categories":[],"readme":"# airtest-douyin\n\n用[Airtest](https://github.com/AirtestProject/Airtest)做点有意思的事情，先来刷个抖音？\n\n![ide01](./images/ide01.png)\n\n## Get Started\n\n### 环境准备\n\n手边没有android手机，iOS又懒得搭[ios-tagent](https://github.com/AirtestProject/iOS-Tagent)的环境，于是采用最偷懒的方式：\n\n*   [夜神模拟器](https://www.yeshen.com/)（可用安卓机代替）\n*   [AirtestIDE](http://airtest.netease.com/)\n\n\n夜神模拟器装上抖音，用起来跟手机上一样舒服。看了下模拟器占内存200m和CPU 12%左右，还不错。夜神自带了一个多开器，后面分布式刷抖音再玩玩\n\n![nox](./images/nox.png)\n\n\n### 录制第一版代码\n\n打开AirtestIDE，按照[文档](http://airtest.netease.com/docs/cn/2_device_connection/3_emulator_connection.html#id2)连接好模拟器\n\n![ide01](./images/ide01.png)\n\n为了每次能用代码自动打开抖音，先用右上角的安卓助手查看一下抖音的package id\n\n![assistant](./images/assistant.png)\n\n手动加上代码\n\n```python\nAPP = \"com.ss.android.ugc.aweme\"\n\nstop_app(APP)\nstart_app(APP)\n```\n\n然后将AirtestIDE调到安卓App的录制模式，进行一些操作，对应的代码就录制下来了\n\n![ide02](./images/ide02.png)\n\n\n### 稍微调整代码\n\n自动录制的代码不太好，稍微调整一下\n\n```python\npoco(boundsInParent=\"[0.03194444444444444, 0.02734375]\").click()\n```\n\n直接改成通过`text`来识别按钮\n\n```python\npoco(text=\"我\").click()\n```\n\n后面的上划操作，改成上划屏幕的``60%``\n\n```python\npoco(\"com.ss.android.ugc.aweme:id/ak2\").swipe([0, -0.6])\n```\n\n然后按`F5`运行一遍，一切正常\n\n\n### 一直刷下去\n\n简单地修改下最后一行代码，就能一直刷下去了\n\n```python\nfor i in range(10):\n    poco(\"com.ss.android.ugc.aweme:id/ak2\").swipe([0, -0.6])\n    sleep(1)\n```\n\n### 好人点个赞\n\n继续用IDE的录制功能，进行点赞操作，生成下面的代码\n\n```python\npoco(\"com.ss.android.ugc.aweme:id/al8\").click()\n```\n\n原来抖音需要登录之后才能点赞，先手动登录吧，代码里面留个`TODO`\n\n```python\nif poco(text=\"输入手机号码\").exists():\n    # TODO: 自动登录\n    print(\"先手动登录一下吧~\")\n    break\n```\n\n![ide03](./images/ide03.png)\n\n\n然后我们截个图留念\n\n```\nsnapshot()\n```\n\n再运行一下，效果非常好\n\n![snapshot](./images/snapshot.png)\n\n\n\u003e tips: 点击IDE工具栏的`log`按钮，你还能看到每步操作的报告。\n\n\n\n### 提交代码\n\n这个脚本里面没有用到图像识别，单个py文件就够了。于是我们从``douyin.air``里面取出代码文件。这样可以用你喜欢的编辑器打开修改，用python直接运行了。\n\n最终代码在[code/douyin.py](./code/douyin.py)，直接python运行。\n\n```shell\npython douyin.py\n```\n\n### To be continued\n\n*   录屏替代截图\n*   多开\u0026分布式\n*   图像识别小姐姐点赞\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMeteorix%2Fairtest-douyin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMeteorix%2Fairtest-douyin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMeteorix%2Fairtest-douyin/lists"}