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.webdriver.common.by import By
- import time
- from selenium_stealth import stealth
- def parse_urls_from_file(file_path):
- try:
- with open(file_path, 'r') as file:
- urls = [line.strip() for line in file if line.strip()]
- return urls
- except FileNotFoundError:
- print(f"File not found: {file_path}")
- return []
- def report_tiktok_videos(video_urls, reason="Misinformation"):
- options = Options()
- options.add_argument("start-maximized")
- # Chrome is controlled by automated test software
- options.add_experimental_option("excludeSwitches", ["enable-automation"])
- options.add_experimental_option('useAutomationExtension', False)
- # avoiding detection
- options.add_argument('--disable-blink-features=AutomationControlled')
- # Default User Profile
- options.add_argument("--profile-directory=Default")
- options.add_argument("--user-data-dir=C:/Users/{{INSERT_USERNAME}}/AppData/Local/Google/Chrome/User Data")
- driver = webdriver.Chrome(options=options)
- stealth(driver, platform='Win32', fix_hairline=True)
- try:
- # Log in to TikTok (requires a manual step)
- print("Opening TikTok login page...")
- driver.get("https://www.tiktok.com/login")
- time.sleep(2) # Wait for manual login (adjust time if needed)
- count = 0
- for url in video_urls:
- # Count is the number of the video
- count += 1
- print(f"{count}. Processing video: {url}")
- driver.get(url)
- time.sleep(3) # Allow video page to load
- try:
- # Pause the video
- pause_button = driver.find_element(By.XPATH, "//div[contains(@class, 'DivPlayIconContainer')]")
- pause_button.click()
- # Locate the "More" button (three dots menu) and click it
- more_button = driver.find_element(By.XPATH,"//div[@aria-haspopup='dialog' and contains(@class, 'DivMoreMenuContainer')]")
- more_button.click()
- time.sleep(1)
- # Locate the "Report" option and click it
- report_option = driver.find_element(By.XPATH, "//span[text()='Report']")
- report_option.click()
- time.sleep(1)
- # Select the reason for reporting (e.g., Misinformation)
- reason_button = driver.find_element(By.XPATH, f"//div[text()='{reason}']")
- reason_button.click()
- time.sleep(1)
- # If "Election misinformation" is a subcategory, select it
- if reason == "Misinformation":
- subcategory_button = driver.find_element(By.XPATH, "//div[text()='Election misinformation']")
- subcategory_button.click()
- time.sleep(1)
- # Confirm the report
- confirm_button = driver.find_element(By.XPATH, "//button[text()='Submit']")
- confirm_button.click()
- time.sleep(1)
- done_button = driver.find_element(By.XPATH, "//button[text()='Done']")
- done_button.click()
- print(f"Successfully reported: {url}")
- except Exception as e:
- print(f"Failed to report {url}. Error: {e}")
- except Exception as e:
- print(f"An error occurred: {e}")
- finally:
- driver.quit()
- if __name__ == "__main__":
- # Path to the file containing TikTok video URLs
- file_path = "url.txt"
- # Parse URLs from the file
- video_list = parse_urls_from_file(file_path)
- # Check if URLs are loaded successfully
- if video_list:
- print(f"Loaded {len(video_list)} video URLs from {file_path}.")
- # Report the videos with the specified reason
- for i in range(1, 20):
- print("Run ", i)
- report_tiktok_videos(video_list, reason="Misinformation")
- else:
- print("No URLs found in the file.")
Add Comment
Please, Sign In to add comment