正确使用时间:Tinder中的过程自动化


我认为许多人都喜欢结识社交。网络和使用应用程序(例如Tinder),
但是喜欢和发送第一条
消息通常会花费很多时间我相信这些都是单调的行为,只会排斥
沟通和约会。如果您是一名程序员,为什么要像其他所有人一样,让
我们一起进行单调动作的过程自动化
,而只将注意力集中在令人愉快的交流上,而要注意一切秩序。

训练


在本文中,我将使用Chrome浏览器
  1. 使用bot_tinder项目创建一个文件夹
  2. bot_tinder chromedriver_for_win chromedriver_for_mac, chromedriver_for_lin (.. 3 Windows, macOS, Linux).
  3. webdriver ( Chrome, Firefox ), .
  4. chromedriver_for_win, chromedriver_for_mac, chromedriver_for_lin.
    , , .. .
  5. bot_tinder文件夹中创建一个名为log.txt的文件(我们写了将转到Tinder的电话号码)。格式不带数字八:9851234567
  6. bot_tinder文件夹中创建tinder.pyfunction.py文件

结果,您应该具有以下内容:



每个文件夹都应包含先前下载的Webdriver文件
如果仅针对您的OS实施它,则webdriver文件应仅位于OS名为“ chromedriver_for_your OS 的文件夹中

实作


tinder.py文件中导入库:

# -*- coding: utf-8-*-
from selenium import webdriver


function.py文件中,导入库:

from selenium.common.exceptions import NoSuchElementException, ElementNotInteractableException
from sys import platform
from time import sleep
import datetime

接下来,在function.py文件中,创建稍后将需要的变量:

error = ''
warning = ''
ok = ''
oc = ''
like = ''
all_sleep = 3
like_sleep = 2
图标已由Habr解释程序删除,但应该是这样的:



您可以从站点复制图标或使用表情符号
变量all_sleeplike_sleep表示延迟时间(以秒为单位)。

function.py文件中创建函数之后


  • 第一个函数将确定日期和时间:
    def get_data_time():
        time_now = datetime.datetime.now()
        return time_now.strftime("%d-%m-%Y %H:%M")

  • 第二个功能将确定您的操作系统并访问所需的网络驱动程序

    def get_OC():
        """
        Define OS.
        :return: OS information and path to chromedriver.exe
        """
        if platform == "linux" or platform == "linux2":
            time_now = datetime.datetime.now()
            information = "[" + get_data_time() + '] {}   Linux'.format(oc)
            put = "chromedriver_for_lin/** webdriver**"
            return information, put
    
        elif platform == "darwin":
            time_now = datetime.datetime.now()
            information = "[" + get_data_time() + '] {}   Mac'.format(oc)
            put = "chromedriver_for_mac/** webdriver**"
            return information, put
    
        elif platform == "win32":
            time_now = datetime.datetime.now()
            information = "[" + get_data_time() + '] {}   Windows'.format(oc)
            put = "chromedriver_for_win/chromedriver.exe"
            return information, put

    切记put变量中写入webdriver的路径

  • 第三个功能将从log.txt文件中读取电话号码

    def information_from_txt_files():
        """
        Read the .txt files
        :return: Information. Login.
        """
        information = ''
        with open('log.txt', 'r') as file:
            log = file.read()
            information += "[" + get_data_time() + \
                           '] {}      Tinder: {}'.format(ok, log) 
        return information, log

  • 第四个功能将关闭Tinder网站上的弹出窗口:

    def close_start_popups(browser):
        """
        Close the popup.
        :param browser: parameter of the running browser.
        :return: information.
        """
        sleep(all_sleep)
        try:
            browser.find_element_by_xpath('//button[@aria-label=""]').click()
            return "[" + get_data_time() + "] {}   .".format(ok)
        except ElementNotInteractableException as err:
            return "[" + get_data_time() + '] {} ' + err + ''.format(error)
        except NoSuchElementException as err:
            return "[" + get_data_time() + '] {}    .'.format(error)

  • 第五个功能将按下“使用电话号码登录”按钮

    def log_in_using_your_phone(browser):
        """
        Click the Login button using the phone number.
        :param browser: parameter of the running browser.
        :return: information
        """
        sleep(all_sleep)
        try:
            browser.find_element_by_xpath('//div[@id="modal-manager"]').find_element_by_xpath('//button[@aria-label="    "]').click()
            return "[" + get_data_time() + "] {}     .".format(ok)
        except ElementNotInteractableException as err:
            return "[" + get_data_time() + '] {} ' + err + ''.format(error)
        except NoSuchElementException as err:
            browser.find_element_by_xpath('//button[text()=" "]').click()
            return log_in_using_your_phone(browser)

  • 第六个功能将输入电话号码:

    def input_number_phone(browser, log):
        """
        Enter the phone number.
        :param browser: parameter of the running browser.
        :param log: phone number.
        :return: information.
        """
        sleep(all_sleep)
        try:
            browser.find_element_by_name('phone_number').send_keys(log)
            return "[" + get_data_time() + '] {}    {}'.format(ok, log)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}      .'.format(error)

  • 第七个功能按下继续按钮

    def go_on(browser):
        """
        Click the Continue button.
        :param browser: parameter of the running browser.
        :return: information
        """
        sleep(all_sleep)
        try:
            browser.find_element_by_xpath('//span[text()=""]').click()
            return "[" + get_data_time() + '] {}   '.format(ok)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}    .'.format(error)

  • 第八项功能要求您输入手机附带的代码:

    def code_check():
        """
        Entering a code and checking the entered code.
        :return: entered code
        """
        kod_numbers = input("[" + get_data_time() + "] {}  : ".format(warning))
        if len(kod_numbers) != 6:
            print("[" + get_data_time() + '] {}   .'.format(error))
            return code_check()
        else:
            print("[" + get_data_time() + '] {}   .'.format(ok))
            return kod_numbers

    该功能还检查输入的位数。
  • 第九个函数输入代码:

    def input_cod(browser):
        """
        Code entry.
        :param browser: parameter of the running browser.
        :return: information.
        """
        try:
            kod_numbers = code_check()
            kod = browser.find_elements_by_xpath('//input[@type="tel"]')
            n = 0
            for i in kod:
                i.send_keys(kod_numbers[n])
                n += 1
            return "[" + get_data_time() + '] {}  .'.format(ok)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}      .'.format(error)

  • 第十个功能允许定义地理位置:

    def geolocation_ok(browser):
        """
        We allow geolocation.
        :param browser: parameter of the running browser.
        :return: information.
        """
        sleep(all_sleep)
        try:
            browser_button = browser.find_elements_by_tag_name("button")
            button_list = {i.text: i for i in browser_button}
            if "" in button_list.keys():
                button = [value for key, value in button_list.items() if key == ""]
                button[0].click()
                return "[" + get_data_time() + '] {}  .'.format(ok)
            else:
                return "[" + get_data_time() + '] {}      .'.format(error)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}      .'.format(error)

  • 第十一功能关闭警报:

    def notice_off(browser):
        """
        Turn off notifications.
        :param browser: parameter of the running browser.
        :return: information.
        """
        sleep(all_sleep)
        try:
            browser_button = browser.find_elements_by_tag_name("button")
            button_list = {i.text: i for i in browser_button}
            if "" in button_list.keys():
                button = [value for key, value in button_list.items() if key == ""]
                button[0].click()
                return "[" + get_data_time() + '] {}  .'.format(ok)
            else:
                return "[" + get_data_time() + '] {}      .'.format(error)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}      .'.format(error)

  • 第十二个功能关闭弹出窗口:

    def popup_windows_off(browser):
        """
        Close popups.
        :param browser: parameter of the running browser
        :return: information
        """
        sleep(like_sleep)
        try:
            browser_button = browser.find_elements_by_tag_name("button")
            button_list = {i.text: i for i in browser_button}
            if "" in button_list.keys():
                button = [value for key, value in button_list.items() if key == ""]
                button[0].click()
                print("[" + get_data_time() + '] {}  .'.format(ok))
        except NoSuchElementException:
            pass

  • 第十三个函数将如下所示:

    def click_like(browser):
        """
        Click LIKE.
        :param browser: parameter of the running browser
        :return: information
        """
        sum_like = 0
        while True:
            try:
                popup_windows_off(browser)
                browser.find_element_by_xpath('//button[@aria-label=""]').click()
                sum_like += 1
                print("[" + get_data_time() + '] {} - {}'.format(like, str(sum_like)))
            except NoSuchElementException:
                print("[" + get_data_time() + '] {}    .'.format(error))


现在转到tinder.py文件并注册所有功能的导入:

from function import get_OC, information_from_txt_files, close_start_popups, notice_off, click_like, log_in_using_your_phone, input_number_phone, go_on, input_cod, geolocation_ok

定义操作系统:
#  
info, put = get_OC()
print(info)

设置浏览器选项:

#    chrome
chromedriver = put
options = webdriver.ChromeOptions()
options.add_argument('--start-minimize')
browser = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)

如果您使用Firefox,请使用selenium.webdriver库阅读如何使用它

浏览器启动并转到“ Tinder”页面:

#        
browser.get('https://tinder.com/app/recs')

现在我们开始使用之前准备的功能:

#  txt   
info_txt, log = information_from_txt_files()
print(info_txt)
#     
print(close_start_popups(browser))
#     
print(log_in_using_your_phone(browser))
#   
print(input_number_phone(browser, log))
#   
print(go_on(browser))
#  
print(input_cod(browser))
#   
print(go_on(browser))
#     
print(geolocation_ok(browser))
#   
print(notice_off(browser))
#  
click_like(browser)

结论


最后,获得一个前往Tinder网站并单击“赞”的机器人。

您只需要花几个小时就可以进入该应用程序,并开始彼此已经很
同情。
自动化是男人努力简化工作,使女人能够做到的。
在下一篇文章中,我们将实现为彼此喜欢的消息发送消息的功能。

All Articles