DEV Community

Cover image for Create Tinder Bot with Python
0xkoji
0xkoji

Posted on

Create Tinder Bot with Python

Watched this youtube video.

The code is based on the video. I added a couple of things to it.

1. Allow a user to input username/password instead of using python file

tinder_bot.py

# input email/username
email_input = self.driver.find_element_by_xpath('//*[@id="email"]')
username = getpass.getpass('please input username\n')
email_input.send_keys(username)

# input password
password_input = self.driver.find_element_by_xpath('//*[@id="pass"]')
password = getpass.getpass('please input password\n')
password_input.send_keys(password)
Enter fullscreen mode Exit fullscreen mode

2. Support 2FA

Can pass the boolean to enable input and click function for 2FA

app.py

two_fa = True # if don't need 2FA just pass False
bot.login(two_fa)
Enter fullscreen mode Exit fullscreen mode

3. Swipe randomly

The video does swipe right simply. I just make that a little bit fun lol

tinder_bot.py

if rand > 0.5:
    try:
        if debug:
            print('swipe like')
        self.like()
    except Exception:
        try:
            self.close_popup()
        except Exception:
            self.close_match()
else:
    if debug:
        print('swipe not like')
    self.not_like()
Enter fullscreen mode Exit fullscreen mode

4. Display action

As you can see, I added debug to show action in the Terminal.

app.py

debug = True # if pass False, prints don't show up
bot.auto_swipe(debug)
Enter fullscreen mode Exit fullscreen mode

5. Screenshot

If the script swipe right, it will take a screenshot and give a random string to a png file.

Alt Text

  1. Get image url from the element (css background-image)
  2. Get a webp and convert it
  3. Save no.2 as a png

tinder_bot.py

def take_screenshot(self):
      filename = self.randomString()+'.png'
      image = self.driver.find_element_by_xpath(
          '//*[@id="content"]/div/div[1]/div/main/div[1]/div/div/div[1]/div/div[1]/div[3]/div[1]/div[1]/div/div[1]/div/div')
      image_url = image.value_of_css_property("background-image")
      raw_url = image_url.replace('url("', '').replace('")', '')
      # get webp
      # convert webp --> png
      resp = requests.get(raw_url)
      im = Image.open(BytesIO(resp.content)).convert("RGB")
      im.save(filename, "png")
Enter fullscreen mode Exit fullscreen mode

From an image, we could get a couple of things like name, age, one-line profile and Instagram username with pytesseract (OCR package)
This is not necessary since we can get them from the website directly lol

6. Terminate

As you may know, Tinder's biz model is a subscription model, so if you don't pay, Tinder will show you a popup that recommends you to purchase a subscription. This script is for fun and I don't use Tinder, so I need to terminate a program instead of aborting by an error.

tinder_bot.py

def not_pay(self):
    popup = self.driver.find_element_by_xpath(
          '//*[@id="modal-manager"]/div/div/div[3]/button[2]')
    popup.click()
    print('cannot swipe any more')
    print('will finish the program')
Enter fullscreen mode Exit fullscreen mode

If you have a Facebook account and Tinder account, you can try this simple Tinder bot.

image

tinder-bot

https://tinder.com/

python and pypi versions

python 3.6.5 selenium 3.141.0 requests 2.22.0 Pillow 6.2.0

requirements

how to use

install webdriver

$ brew cask install chromedriver
# check version
$ chromedriver --version
Enter fullscreen mode Exit fullscreen mode

run python script

$ git clone https://github.com/koji/tinder-bot.git
$ cd tinder-bot
$ pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Maybe you are interested in doing something with javascript instead of using python.

Icons made by Freepik from www.flaticon.com

Top comments (0)