Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.chrome.options import Options
- from selenium_stealth import stealth
- from fake_useragent import UserAgent
- import random
- import time
- from selenium.webdriver.common.action_chains import ActionChains
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- def human_delay(min_delay=1, max_delay=3):
- """Simulate human delay."""
- delay = random.uniform(min_delay, max_delay)
- time.sleep(delay)
- def run_script():
- # Initialize fake_useragent to randomize the user-agent
- ua = UserAgent()
- user_agent = ua.random
- # Set up Chrome options
- options = Options()
- options.add_argument("--disable-blink-features=AutomationControlled") # Hides bot automation
- options.add_argument(f"user-agent={user_agent}") # Randomize user agent
- options.add_argument("--start-maximized") # Maximizes the window for realism
- options.add_argument("--disable-extensions") # Disables extensions
- options.add_argument("--disable-gpu") # Disable GPU
- options.add_argument("--incognito") # Incognito mode for added privacy
- options.add_argument("window-size=1920x1080") # Set window size
- options.add_argument("--disable-infobars") # Disable info bars
- options.add_argument("--disable-popup-blocking") # Disable popups
- # Disable the "Chrome is being controlled by automated software" banner
- options.add_experimental_option("excludeSwitches", ["enable-automation"])
- options.add_experimental_option("useAutomationExtension", False)
- options.add_argument("--disable-dev-shm-usage")
- options.add_argument("--no-sandbox")
- options.add_argument("--remote-debugging-port=9222") # Make sure the debugger is not paused
- # Set up WebDriver
- driver = webdriver.Chrome(options=options)
- # Apply stealth settings to avoid detection
- stealth(driver,
- user_agent=user_agent,
- languages=["en-US", "en"],
- vendor="Google Inc.",
- platform="Win32",
- webgl_vendor="Intel Inc.",
- renderer="Intel Iris OpenGL Engine",
- fix_hairline=True)
- try:
- # Open the target URL
- driver.get("https://watchseries.bar/movie/the-wild-robot/1184918")
- # Inject JavaScript to remove any debugger statements
- driver.execute_script("""
- // Remove all debugger statements from the page to avoid interruption
- var scripts = document.getElementsByTagName('script');
- for (var i = 0; i < scripts.length; i++) {
- scripts[i].textContent = scripts[i].textContent.replace(/debugger;/g, '');
- }
- """)
- print("[ + ] Injected JavaScript to remove debugger statements.")
- # Simulate a random window size for realism
- width = random.randint(1024, 1920)
- height = random.randint(768, 1080)
- driver.set_window_size(width, height)
- # Wait for the page to fully load (wait until a specific element is visible)
- WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, '//*[@id="player"]/div[2]')))
- print("[ + ] Page fully loaded, element is visible.")
- # Wait before interacting with elements
- human_delay(2, 3)
- print("[ +] Waited for 2-3 seconds before interacting with elements.")
- # Simulate mouse movement (move mouse around)
- actions = ActionChains(driver)
- actions.move_by_offset(10, 10).perform() # Move mouse slightly to simulate activity
- actions.move_by_offset(-10, -10).perform() # Slight delay to simulate loading time
- print("[ + ] Simulated mouse movement.")
- # Find and click on the button
- try:
- button = driver.find_element(By.XPATH, '//*[@id="player"]/div[2]')
- button.click()
- print("Button clicked successfully.")
- except Exception as e:
- print(f"Could not find or click the button: {e}")
- # Wait for 5 minutes to simulate watching or processing the video
- time.sleep(300) # 300 seconds = 5 minutes
- print("[ + ] Waited for 5 minutes to simulate watching the video.")
- finally:
- # Close the driver after the wait time
- driver.quit()
- print("[ + ] Driver closed successfully.")
- if __name__ == "__main__":
- run_script()
Advertisement
Add Comment
Please, Sign In to add comment