Advertisement
Tryhell

pfaimwh

Feb 3rd, 2020 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. import requests
  2. import chromedriver_autoinstaller
  3. from selenium import webdriver
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. from selenium.webdriver.support import expected_conditions as EC
  7. from selenium.common.exceptions import NoSuchElementException, TimeoutException
  8. import time
  9. import threading
  10.  
  11. lock = threading.Lock()
  12.  
  13. def get_key():
  14. response = requests.get("http://192.168.11.141/hot.php")
  15. return response.text.strip()
  16.  
  17. def create_browser():
  18. chromedriver_autoinstaller.install()
  19. options = webdriver.ChromeOptions()
  20. options.add_argument("--no-sandbox")
  21. options.add_argument("--disable-dev-shm-usage")
  22. options.add_argument("--start-maximized")
  23. options.add_argument("--disable-infobars")
  24. options.add_argument("--disable-extensions")
  25. options.add_experimental_option("excludeSwitches", ["enable-automation"])
  26. options.add_argument("--proxy-server=192.168.11.69:8888")
  27. return webdriver.Chrome(options=options)
  28.  
  29. def wait_for_xpath_and_click(browser, xpath, timeout=120):
  30. wait = WebDriverWait(browser, timeout)
  31. try:
  32. element = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
  33. element.click()
  34. return True
  35. except TimeoutException:
  36. return False
  37.  
  38. def check_button_active(browser, xpath):
  39. try:
  40. browser.find_element(By.XPATH, xpath + "[not(@disabled)]")
  41. return True
  42. except NoSuchElementException:
  43. return False
  44.  
  45. def wait_for_optional_xpath_and_click(browser, xpath, timeout=10):
  46. wait = WebDriverWait(browser, timeout)
  47. try:
  48. element = wait.until(EC.element_to_be_clickable((By.XPATH, xpath)))
  49. element.click()
  50. return True
  51. except TimeoutException:
  52. return False
  53.  
  54. def browser_task():
  55. browser = create_browser()
  56. while True:
  57. try:
  58. browser.get("https://tgapp.herewallet.app/auth/import")
  59. time.sleep(1)
  60.  
  61. key = get_key()
  62. input_field_xpath = "//*[@id='root']/div/div[1]/label/textarea"
  63. browser.find_element(By.XPATH, input_field_xpath).send_keys(key)
  64.  
  65. if not wait_for_xpath_and_click(browser, "//*[@id='root']/div/div[2]/button"):
  66. raise Exception("Button not found, restarting...")
  67.  
  68. if wait_for_optional_xpath_and_click(browser, "//*[@id='root']/div/button", timeout=20):
  69. print("Optional button clicked")
  70. else:
  71. print("Optional button not found or not clickable")
  72.  
  73. if not wait_for_xpath_and_click(browser, "//*[@id='root']/div/div/div/div[4]/div[1]"):
  74. raise Exception("Element not found, restarting...")
  75.  
  76. next_button_xpath = "//*[@id='root']/div/div[2]/div/div[3]/div/div[2]/div[2]/button"
  77. if not check_button_active(browser, next_button_xpath):
  78. raise Exception("Button not active, restarting...")
  79.  
  80. if not wait_for_xpath_and_click(browser, next_button_xpath):
  81. raise Exception("Next button not found or not clickable, restarting...")
  82.  
  83. optional_button_xpath = "/html/body/div[3]/div/div[2]/div/div/div[2]/button"
  84. wait_for_optional_xpath_and_click(browser, optional_button_xpath)
  85.  
  86. time.sleep(60)
  87.  
  88. browser.delete_all_cookies()
  89. except Exception as e:
  90. print(e)
  91. browser.quit()
  92. browser = create_browser()
  93.  
  94. def main():
  95. threads = []
  96. for _ in range(5): # Уменьшено количество потоков для снижения нагрузки
  97. t = threading.Thread(target=browser_task)
  98. t.start()
  99. threads.append(t)
  100.  
  101. for t in threads:
  102. t.join()
  103.  
  104. if __name__ == "__main__":
  105. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement