This python bot can automate the liking and disliking on tinder using Selenium.

You can find the link to github repository with full script at the bottom of this post. This article explains the concepts used to code this script.

Disclaimer: This is for educational and informational purposes only.

Requirements

  • Selenium
  • Chrome Webdriver

Selenium | Automate the Browser

This is the one two requirements for this script to work. Selenium will help us automate the browser.

Use pip to install this requirement:

pip install selenium

Other than selenium, you also need to download chromedriver for your respective OS from chromium.org.

Initializing the Selenium driver

Initializing the selenium driver for tinder bot is pretty straight forward, just import the webdriver from selenium and create a Chrome instance by passing the chromedriver you just downloaded.

class TinderBot:
    """ Tinder bot class with all the methods"""
    def __init__(self):
        """Method to initialize chrome webdriver with settings"""
        chrome_options = Options()
        # This will create a new profile in your chrome browser
        chrome_options.add_argument(
            "--user-data-dir=C:\\Users\\username\\AppData\\Local\\Google Selenium\\Chrome\\User Data"
        )
        chrome_options.add_argument(
            "--profile-directory=Default"
        )
        self.driver = webdriver.Chrome(
            executable_path="chromedriver.exe",  # Path to your chrome driver
            chrome_options=chrome_options
        )

And with this your selenium driver is ready to automate tinder.

The Automatic Swiping

This was again a very simple task. Just find the xPath of the like and dislike button by visiting developer option in chrome and set the Xpath values in the script.

LIKE_BUTTON_XPATH = '//*[@id="content"]/div/div[1]/div/main/div[1]/div/div/div[1]/div/div[2]/div[4]/button'
DISLIKE_BUTTON_XPATH = '//*[@id="content"]/div/div[1]/div/main/div[1]/div/div/div[1]/div/div[2]/div[2]/button'

Preventing Bot Detection

So to prevent Tinder.com from detecting our bot there are couple things that are done.

Set User Agent

When initializing our selenium webdriver we can set a user agent so that tinder servers won’t get request from selenium webdriver and get request from a normal chrome web browser.

  chrome_options.add_argument(
            '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.'
            '4044.113 Safari/537.36'
   )

Adding Randomness in Tinder Bot

So we need the bot to behave less robotic-ally.

Random Sleeping

For this, I created a function which sleeps for random seconds between actions.

    def rand_sleep(self):
        """
        Method to sleep randomly between 1 to 3 seconds (float)
        This randomness prevents our bot from getting detected by tinder
        :return:
        """
        sleep_sec = random.uniform(1, 3)
        print('Sleeping for {} seconds'.format(str(sleep_sec)))
        sleep(sleep_sec)

Random Swiping

Tinder will detect the bot if it is swiping all the profiles right. So for that there is a probability set for swiping left or right. This can be updated.

rand = random.random()
                if rand < .80:  
                    self.swipe_right()
                else:
                    self.swipe_left()

Handling Exceptions

I have handled ElementClickInterceptedException which occurs when there in an unexpected element on the screen. Here we can just refresh the page and restart the process.

It Works!!

Of course, you would need gold for unlimited swipes otherwise the script will run only for few minutes.

What next for Tinder Bot?

There are two things in which this script can be evolved:

  1. Automating Conversations with Cleverbot or DialogFlow
  2. Training the bot to swipe as per the user behaviour

Here is the link to github repository with full code: https://github.com/abhibalani/tinder-bot-python

Share:

administrator

I am a full stack software engineer and a blogger. Primarily, I work on Python, Java and React.js. I am an autodidact with a strong passion for new technologies. I love to build new things from the ground up. I have about 7 years of dynamic experience gained by working in early stage startups to mid-sized organizations in an Agile environment.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.