Douyin automatic likes and comments crawler project
If you get tired of watching videos, or want to learn how to use code to control the interface of a real mobile app, this article is for you. We will start from scratch, using a real Android phone, a data cable, and a few Python codes to build a scalable, anti-blocking logic, and built-in local data recording Douyin automation framework.
But before touching the keyboard, the most serious warning must be placed here.
⚠️ Fatal Warning This project** is only used to learn UI automation technology and Python project architecture design**. The automated like, comment, and follow operations of short video platforms such as Douyin directly violate their "User Agreement", "Community Standards" and even some laws and regulations**. If you use the code for any commercial or illegal purposes, your account may be permanently banned, your device IP may be restricted, and you may even face legal liability**. **Please do not take the law personally. All consequences are borne by the user. **
Why choose this solution?
Many friends who are new to automation will think of two common approaches:
- Simulator + Group Control Script The advantage is that it can be operated in batches, but the device fingerprints (IMEI, MAC, CPU model, etc.) of the simulator are highly unified, and Douyin’s risk control system can identify them at a glance.
- Packet Capture/Crack API
Need research
X-Gorgon、X-Ladon、A-BogusThe maintenance cost is extremely high due to the ever-changing encryption algorithms, and even slightly frequent API calls will trigger risk control.
We chose the third route for this project: Use uiautomator2 to directly drive the native interface on a real Android phone. There are three major benefits to doing this:
- ✅ No need to root or jailbreak, just any idle Android machine, the device fingerprint is completely authentic.
- ✅ All operations simulate a real person's "swipe → stay → click → enter", and the behavioral characteristics are extremely difficult to identify as scripts.
- ✅ All written in Python, the logic is clear, easy to modify and expand, and it is very convenient to add OCR recognition and scheduled tasks later.
Project structure: five modules to handle everything
The entire system is designed to be very streamlined. Even if you have just learned Python, you can still understand the relationship between each part.
We only need to focus on three core modules:
- ActionConfig: Centrally manage parameters such as like probability, daily upper limit, and comments. Subsequent parameter adjustments only need to be changed in one place.
- DatabaseManager: Use SQLite to record how many times you interacted today and which videos you interacted with, to prevent overshooting or repeated operations.
- DouyinAutoBot: Communicate with the mobile phone through uiautomator2 to perform all sliding, clicking, and input actions.
From preparation to run-through: complete code disassembly
0. Preparation: Let the computer control the mobile phone
Before you start writing code, make sure the device can connect properly:
- Open the Developer Options of your phone, find USB Debugging and USB Installation, and turn them on. (Different brands have different entrances. Searching for "Developer Options" directly in the settings is the fastest.)
- Install the ADB driver on your computer.
- Windows 10/11 is usually installed automatically after plugging in the USB;
- macOS/Linux via Android Studio toolkit or directly
brew install android-platform-tools/apt install adbInstall.
- Connect the mobile phone with a data cable and enter in the terminal/command line:
If you see something likeemulator-5554(emulator) or12345678The output of (real mobile phone) indicates that the connection is successful.
1. Configuration center: extract all changed parameters
Hard-coded numbers can make adjustments later very painful. We use PythondataclassCentrally manage probability, duration, and comment text.
2. Data steward: Use SQLite to record every interaction
Recording interactions is not a “frills extra”. With it, you can check at any time how many operations have been performed today and whether it has exceeded the threshold. It can also be used for subsequent analysis of why it was risk controlled.
3. Control the mobile phone: Use uiautomator2 to simulate real-person operation
This is the most important part of the entire project. In order to avoid being recognized as a script by the platform, all swipes, clicks, and waiting times must be added with random offsets.
💡 In actual development, it is recommended to use Airtest image template matching or uiautomator2's text/desc positioning to replace fixed coordinates. However, Douyin's interface element IDs often change, and fixed coordinate demonstrations are more convenient to understand.
Anti-blocking strategy: Don’t let the platform target you
Basic protections such as daily upper limit, random sliding, and random waiting have been added to the code, but if you want to be more secure, you have to work on your usage habits:
-
Control usage period It only runs during 1
2 fixed leisure periods every day, such as 19:0020:30, 22:00~22:40 in the evening, and a single session does not exceed 30 minutes. Never run 24 hours a day. -
Diversified action combinations Don't like every time. You can occasionally just watch the interaction, occasionally like and then add comments, or even simulate a "like and then cancel" operation to make the behavior look more like real users.
-
Hardware selection is important The device fingerprints of the simulator are highly unified, and the secret will be revealed as soon as the risk control checks. The safest thing is to use an old idle Android phone, each one has an independent fingerprint.
-
Do not reuse network environments Do not connect multiple accounts to the same WiFi. Try to use different IPs or even different mobile phone cards to spread the risk.
-
Comment content should be "Watch the video and then cook" If comments can be combined with video content, the authenticity will be greatly improved. For example, if you identify food keywords through OCR, you can post "It looks delicious" and "Favourite the recipe." This is an advanced gameplay, but it can take the anti-blocking ability to another two levels.
Run quickly
- Combine the above three code blocks into one
douyin_bot.pydocument. - Create a new one
requirements.txt, write:
- Install dependencies:
- Verify after connecting to the mobile phone:
- Start the program:
Summarize
This article takes you through a low threshold, modular, and built-in anti-blocking logic Douyin UI automation framework. You can learn:
- How uiautomator2 controls a real phone
- How to use dataclass and SQLite to build maintainable configuration and data layers
- Basic anti-sealing design ideas in real projects
Again: **This project is only for technical learning and should not be used in any production environment or violation scenarios. ** If you want more stable image recognition positioning, Docker scheduled deployment and other advanced functions, you can continue to expand based on this framework.
I hope this tutorial can help you open the door to Android UI automation.

