Guest User

Untitled

a guest
Nov 9th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.options import Options
  3. from selenium_stealth import stealth
  4. from fake_useragent import UserAgent
  5. import random
  6. import time
  7. from selenium.webdriver.common.action_chains import ActionChains
  8. from selenium.webdriver.common.by import By
  9. from selenium.webdriver.support.ui import WebDriverWait
  10. from selenium.webdriver.support import expected_conditions as EC
  11.  
  12. def human_delay(min_delay=1, max_delay=3):
  13. """Simulate human delay."""
  14. delay = random.uniform(min_delay, max_delay)
  15. time.sleep(delay)
  16.  
  17. def run_script():
  18. # Initialize fake_useragent to randomize the user-agent
  19. ua = UserAgent()
  20. user_agent = ua.random
  21.  
  22. # Set up Chrome options
  23. options = Options()
  24. options.add_argument("--disable-blink-features=AutomationControlled") # Hides bot automation
  25. options.add_argument(f"user-agent={user_agent}") # Randomize user agent
  26. options.add_argument("--start-maximized") # Maximizes the window for realism
  27. options.add_argument("--disable-extensions") # Disables extensions
  28. options.add_argument("--disable-gpu") # Disable GPU
  29. options.add_argument("--incognito") # Incognito mode for added privacy
  30. options.add_argument("window-size=1920x1080") # Set window size
  31. options.add_argument("--disable-infobars") # Disable info bars
  32. options.add_argument("--disable-popup-blocking") # Disable popups
  33.  
  34. # Disable the "Chrome is being controlled by automated software" banner
  35. options.add_experimental_option("excludeSwitches", ["enable-automation"])
  36. options.add_experimental_option("useAutomationExtension", False)
  37. options.add_argument("--disable-dev-shm-usage")
  38. options.add_argument("--no-sandbox")
  39. options.add_argument("--remote-debugging-port=9222") # Make sure the debugger is not paused
  40.  
  41. # Set up WebDriver
  42. driver = webdriver.Chrome(options=options)
  43.  
  44. # Apply stealth settings to avoid detection
  45. stealth(driver,
  46. user_agent=user_agent,
  47. languages=["en-US", "en"],
  48. vendor="Google Inc.",
  49. platform="Win32",
  50. webgl_vendor="Intel Inc.",
  51. renderer="Intel Iris OpenGL Engine",
  52. fix_hairline=True)
  53.  
  54. try:
  55. # Open the target URL
  56. driver.get("https://watchseries.bar/movie/the-wild-robot/1184918")
  57.  
  58. # Inject JavaScript to remove any debugger statements
  59. driver.execute_script("""
  60. // Remove all debugger statements from the page to avoid interruption
  61. var scripts = document.getElementsByTagName('script');
  62. for (var i = 0; i < scripts.length; i++) {
  63. scripts[i].textContent = scripts[i].textContent.replace(/debugger;/g, '');
  64. }
  65. """)
  66. print("[ + ] Injected JavaScript to remove debugger statements.")
  67.  
  68. # Simulate a random window size for realism
  69. width = random.randint(1024, 1920)
  70. height = random.randint(768, 1080)
  71. driver.set_window_size(width, height)
  72.  
  73. # Wait for the page to fully load (wait until a specific element is visible)
  74. WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, '//*[@id="player"]/div[2]')))
  75. print("[ + ] Page fully loaded, element is visible.")
  76.  
  77. # Wait before interacting with elements
  78. human_delay(2, 3)
  79. print("[ +] Waited for 2-3 seconds before interacting with elements.")
  80.  
  81. # Simulate mouse movement (move mouse around)
  82. actions = ActionChains(driver)
  83. actions.move_by_offset(10, 10).perform() # Move mouse slightly to simulate activity
  84. actions.move_by_offset(-10, -10).perform() # Slight delay to simulate loading time
  85. print("[ + ] Simulated mouse movement.")
  86.  
  87. # Find and click on the button
  88. try:
  89. button = driver.find_element(By.XPATH, '//*[@id="player"]/div[2]')
  90. button.click()
  91. print("Button clicked successfully.")
  92. except Exception as e:
  93. print(f"Could not find or click the button: {e}")
  94.  
  95. # Wait for 5 minutes to simulate watching or processing the video
  96. time.sleep(300) # 300 seconds = 5 minutes
  97. print("[ + ] Waited for 5 minutes to simulate watching the video.")
  98.  
  99. finally:
  100. # Close the driver after the wait time
  101. driver.quit()
  102. print("[ + ] Driver closed successfully.")
  103.  
  104. if __name__ == "__main__":
  105. run_script()
  106.  
Advertisement
Add Comment
Please, Sign In to add comment