main.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import time
  2. import random
  3. import os
  4. from datetime import datetime
  5. from selenium import webdriver
  6. # https://pypi.org/project/webdriver-manager/
  7. from webdriver_manager.chrome import ChromeDriverManager
  8. from fake_useragent import UserAgent
  9. def time_watcher():
  10. print('--- %s seconds ---' % (time.time() - start_time))
  11. def start_bot(browser, wallet):
  12. # обработка клика по кнопке BTC-кран
  13. time.sleep(get_time_await())
  14. # путь до кнопки
  15. path_button = '//*[@id="tab_bonus"]/a/span'
  16. browser.find_element_by_xpath(path_button).click()
  17. # вставляем номер BTC-кошелька в input
  18. time.sleep(get_time_await())
  19. browser.find_element_by_id('bonus_purse').send_keys(wallet)
  20. # обработка клика по кнопке "Получить бонус"
  21. time.sleep(get_time_await())
  22. browser.find_element_by_id('bonus_button').click()
  23. # обработка клика по квадратику "для проверки"
  24. time.sleep(10)
  25. path_check = '//*[@id="bonus_form"]/div[4]/div[1]'
  26. browser.find_element_by_xpath(path_check).click()
  27. # обработка повторного клика по кнопке "Получить бонус"
  28. time.sleep(5)
  29. browser.find_element_by_id('bonus_button').click()
  30. # закрываем Selenium
  31. time.sleep(get_time_await())
  32. get_data(browser)
  33. def write_log(log, nameFile): # запись log'a в файл
  34. path_f = os.path.dirname(os.path.abspath(__file__))
  35. with open(os.path.join(path_f, nameFile), "a", encoding='utf-8') as _file:
  36. _file.write(log)
  37. def get_time_await():
  38. time_await = random.uniform(2, 4)
  39. print(f'time_await: {time_await}\n')
  40. return time_await
  41. def get_data(browser):
  42. try:
  43. getted = browser.find_element_by_id(
  44. 'bonus_stats').find_element_by_tag_name('b').get_attribute("title")
  45. except:
  46. getted = "None"
  47. try:
  48. balance = browser.find_element_by_id(
  49. 'faucet_unpaid_balance').find_element_by_tag_name('b').get_attribute("title")
  50. except:
  51. balance = "None"
  52. now = datetime.now()
  53. data_time = now.strftime("%H:%M:%S %d-%m-%Y")
  54. write_log(
  55. f"{data_time} | getted: {getted} | balance: {balance}\n", "log.txt")
  56. def setup_browser(proxy=None):
  57. # подмена UserAgent
  58. ua = UserAgent()
  59. # user_agent = ua.random
  60. user_agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2226.0 Safari/537.36'
  61. # установка proxy
  62. if proxy != None:
  63. PROXY = proxy
  64. webdriver.DesiredCapabilities.CHROME['proxy'] = {
  65. "httpProxy": PROXY,
  66. "ftpProxy": PROXY,
  67. "sslProxy": PROXY,
  68. "proxyType": "MANUAL"}
  69. options = webdriver.ChromeOptions()
  70. options.add_argument(f"--user-agent={user_agent}")
  71. options.add_argument("--start-maximized")
  72. driver = webdriver.Chrome(chrome_options=options,
  73. executable_path=ChromeDriverManager().install())
  74. return driver
  75. def main():
  76. url = 'https://www.bestchange.ru/'
  77. proxy = 'http://175.106.18.201:38708'
  78. wallet = '3KBgUTDQWZDhMqBDqs2LCHwuQhYtDoY7KX'
  79. browser = setup_browser()
  80. browser.get(url)
  81. start_bot(browser, wallet)
  82. if __name__ == '__main__':
  83. start_time = time.time()
  84. main()
  85. time_watcher()