Guest User

main.py

a guest
Dec 2nd, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.options import Options
  3. from selenium.webdriver.common.by import By
  4. import time
  5.  
  6. from selenium_stealth import stealth
  7.  
  8.  
  9. def parse_urls_from_file(file_path):
  10.  
  11. try:
  12. with open(file_path, 'r') as file:
  13. urls = [line.strip() for line in file if line.strip()]
  14. return urls
  15. except FileNotFoundError:
  16. print(f"File not found: {file_path}")
  17. return []
  18.  
  19.  
  20. def report_tiktok_videos(video_urls, reason="Misinformation"):
  21. options = Options()
  22. options.add_argument("start-maximized")
  23.  
  24. # Chrome is controlled by automated test software
  25. options.add_experimental_option("excludeSwitches", ["enable-automation"])
  26. options.add_experimental_option('useAutomationExtension', False)
  27.  
  28. # avoiding detection
  29. options.add_argument('--disable-blink-features=AutomationControlled')
  30.  
  31. # Default User Profile
  32. options.add_argument("--profile-directory=Default")
  33. options.add_argument("--user-data-dir=C:/Users/{{INSERT_USERNAME}}/AppData/Local/Google/Chrome/User Data")
  34.  
  35.  
  36. driver = webdriver.Chrome(options=options)
  37. stealth(driver, platform='Win32', fix_hairline=True)
  38.  
  39. try:
  40. # Log in to TikTok (requires a manual step)
  41. print("Opening TikTok login page...")
  42. driver.get("https://www.tiktok.com/login")
  43. time.sleep(2) # Wait for manual login (adjust time if needed)
  44.  
  45. count = 0
  46. for url in video_urls:
  47. # Count is the number of the video
  48. count += 1
  49. print(f"{count}. Processing video: {url}")
  50.  
  51. driver.get(url)
  52. time.sleep(3) # Allow video page to load
  53.  
  54. try:
  55. # Pause the video
  56. pause_button = driver.find_element(By.XPATH, "//div[contains(@class, 'DivPlayIconContainer')]")
  57. pause_button.click()
  58.  
  59. # Locate the "More" button (three dots menu) and click it
  60. more_button = driver.find_element(By.XPATH,"//div[@aria-haspopup='dialog' and contains(@class, 'DivMoreMenuContainer')]")
  61. more_button.click()
  62. time.sleep(1)
  63.  
  64. # Locate the "Report" option and click it
  65. report_option = driver.find_element(By.XPATH, "//span[text()='Report']")
  66. report_option.click()
  67. time.sleep(1)
  68.  
  69. # Select the reason for reporting (e.g., Misinformation)
  70. reason_button = driver.find_element(By.XPATH, f"//div[text()='{reason}']")
  71. reason_button.click()
  72. time.sleep(1)
  73.  
  74. # If "Election misinformation" is a subcategory, select it
  75. if reason == "Misinformation":
  76. subcategory_button = driver.find_element(By.XPATH, "//div[text()='Election misinformation']")
  77. subcategory_button.click()
  78. time.sleep(1)
  79.  
  80. # Confirm the report
  81. confirm_button = driver.find_element(By.XPATH, "//button[text()='Submit']")
  82. confirm_button.click()
  83. time.sleep(1)
  84.  
  85. done_button = driver.find_element(By.XPATH, "//button[text()='Done']")
  86. done_button.click()
  87.  
  88. print(f"Successfully reported: {url}")
  89. except Exception as e:
  90. print(f"Failed to report {url}. Error: {e}")
  91.  
  92. except Exception as e:
  93. print(f"An error occurred: {e}")
  94. finally:
  95. driver.quit()
  96.  
  97.  
  98. if __name__ == "__main__":
  99. # Path to the file containing TikTok video URLs
  100. file_path = "url.txt"
  101.  
  102. # Parse URLs from the file
  103. video_list = parse_urls_from_file(file_path)
  104.  
  105. # Check if URLs are loaded successfully
  106. if video_list:
  107. print(f"Loaded {len(video_list)} video URLs from {file_path}.")
  108. # Report the videos with the specified reason
  109. for i in range(1, 20):
  110. print("Run ", i)
  111. report_tiktok_videos(video_list, reason="Misinformation")
  112. else:
  113. print("No URLs found in the file.")
  114.  
Add Comment
Please, Sign In to add comment