Get More Followers, Likes, and Views on TikTok with a Simple Python Script

I built a simple Python script designed to automatically comment on random TikTok videos as a way to experiment with engagement and visibility. This lightweight automation script is written in less than 40 lines of Python code and uses basic modules such as time and pyautogui.

The script works by simulating human actions on the TikTok desktop app, including scrolling through videos and posting random positive quotes in the comment section. While the script is also capable of liking videos, I chose to focus only on commenting, since leaving comments tends to generate more noticeable engagement without needing to like every video.

This bot was tested on Windows using the TikTok desktop application, but it can also work with the browser version of TikTok. Keep in mind that you may need to adjust the PyAutoGUI screen coordinates depending on your screen resolution, display scaling, and file locations, as these values vary from system to system.

Overall, this simple Python automation project demonstrates how basic scripting can be used to explore engagement patterns on social media platforms and highlights how consistency and interaction play a major role in TikTok growth.

import pyautogui
import time
import random

x = pyautogui.position()
print(x)

file1 = open('C:/Users/david/OneDrive/Documents/tiktok_bot/comments.txt', 'r')
Lines = file1.readlines()
count = 0

  
for line in Lines:
    count += 1
    dwn = pyautogui.locateOnScreen('C:/Users/david/OneDrive/Documents/tiktok_bot/down.png')

    pyautogui.click(dwn) # click on the down button
    time.sleep(3)
    # pyautogui.click(907, 589) # click to like the short
    # time.sleep(3)
    pyautogui.click(1171, 978) # click on write comment box
    time.sleep(3)
    try:
        pyautogui.write(line.strip(), interval=0.25)

        time.sleep(3)
        
        bl = pyautogui.locateOnScreen('C:/Users/david/OneDrive/Documents/tiktok_bot/post3.png')

        pyautogui.click(bl) # click on post button
    except:
        pass
    time.sleep(3)

Doc:

The first file you’ll need is the comment.txt file, which you can download for free below.

Getting the Correct Screen Coordinates

To make sure the bot clicks exactly where it’s supposed to, I added a small PyAutoGUI helper function:

x = pyautogui.position()
print(x)

This function continuously prints the X and Y screen coordinates of your mouse cursor in the terminal. You can use it to identify the precise location of buttons and input fields inside the TikTok desktop app or browser.

Important:
When using this function, make sure to temporarily comment out the rest of the script so that only these two lines run. This prevents the bot from executing any clicks or scrolling while you are collecting coordinates.

Once you move your mouse cursor over the correct location—such as the Like button or the comment input box—the terminal will display the exact coordinates. You can then copy those values and update them in the script.

For example:

pyautogui.click(907, 589)  # Click to like the video (optional)
pyautogui.click(1171, 978)  # Click on the comment input box

This step is essential because screen resolution, scaling, and window size differ from one computer to another. Using your own coordinates ensures the bot interacts with the correct elements every time.

Using time.sleep()

The time.sleep(3) function is used with Python’s time module to pause the script for 3 seconds before moving on to the next task.

This delay helps ensure that each action—such as scrolling, clicking, or typing—has enough time to complete before the script continues running. Without these pauses, the bot may move too quickly and miss elements on the screen.

You can adjust the number inside time.sleep() to make the bot run slower or faster, depending on your system’s performance and internet speed.

Locating the Post Button with locateOnScreen()

bl = pyautogui.locateOnScreen('C:/Users/david/OneDrive/Documents/tiktok_bot/post3.png')

This function uses PyAutoGUI’s image recognition to locate the Post button on TikTok. Since TikTok can change the position of the Post button—and sometimes even its design—hard-coding coordinates is not always reliable.

Instead, you can take a screenshot of the Post button and save it as an image file. The script then scans the screen for that image and automatically detects where the button is located. Once found, the bot knows exactly where to click in order to post the comment.

This approach makes the script more flexible and resilient to layout changes, especially when TikTok updates its interface or displays the button in slightly different positions.

Download the image for post3.png bellow

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top