| 9 | import requests |
| 10 | |
| 11 | class KickBot(): |
| 12 | def __init__(self, url): |
| 13 | self.url = url |
| 14 | self.driver = None |
| 15 | |
| 16 | def setupWebBrowser(self): |
| 17 | chrome_options = Options() |
| 18 | chrome_options.add_argument("--headless") |
| 19 | chrome_options.add_argument("--mute-audio") |
| 20 | chrome_options.add_argument("--no-sandbox") |
| 21 | chrome_options.add_argument("--disable-dev-shm-usage") |
| 22 | chrome_options.add_argument("--disable-gpu") |
| 23 | self.driver = uc.Chrome(options=chrome_options) |
| 24 | |
| 25 | def getToken(self): |
| 26 | referer = self.driver.current_url |
| 27 | response = requests.get(referer) |
| 28 | csrf_token = response.headers.get('X-CSRFToken') |
| 29 | return csrf_token |
| 30 | |
| 31 | def doTest(self): |
| 32 | self.setupWebBrowser() |
| 33 | self.driver.get(self.url) |
| 34 | not_found_count = 0 |
| 35 | csrf_token = self.getToken() |
| 36 | while True: |
| 37 | try: |
| 38 | |
| 39 | button = self.driver.find_element(By.CSS_SELECTOR, "button.variant-action.size-sm") |
| 40 | |
| 41 | button.click() |
| 42 | print("Button clicked!") |
| 43 | not_found_count = 0 |
| 44 | except NoSuchElementException: |
| 45 | |
| 46 | if "Oops, Something went wrong" in self.driver.page_source: |
| 47 | self.driver.refresh() |
| 48 | print("Page refreshed!") |
| 49 | not_found_count = 0 |
| 50 | elif not_found_count >= 10: |
| 51 | print("Watch now button not found after 10 attempts. Stopping search.") |
| 52 | break |
| 53 | elif "Checking if the site connection is secure" in self.driver.page_source: |
| 54 | self.driver.close() |
| 55 | sleep(5) |
| 56 | self.setupWebBrowser() |
| 57 | self.driver.get(self.url) |
| 58 | print("Browser restarted") |
| 59 | csrf_token = self.getToken() |
| 60 | else: |
| 61 | print("Watch now button not found on this page") |
| 62 | not_found_count += 1 |
| 63 | sleep(10) |
| 64 | |
| 65 | |
| 66 | self.driver.execute_script("document.querySelector('#vjs_video_3 > div:nth-child(1) > video').style.display = 'none'") |
| 67 | |
| 68 | |