watch_yt.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import time
  2. import json
  3. from selenium import webdriver
  4. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  5. import time
  6. import os
  7. import urllib.parse
  8. from selenium.webdriver.support.ui import WebDriverWait
  9. from selenium.webdriver.common.by import By
  10. from selenium.webdriver.support import expected_conditions as EC
  11. from selenium.webdriver.common.keys import Keys
  12. import codecs
  13. import random
  14. import requests
  15. import datetime
  16. import dataset
  17. import time
  18. import traceback
  19. import sys
  20. import fire
  21. def init_browser():
  22. os.system('docker container restart proxy1')
  23. os.system('docker container restart tiny1')
  24. time.sleep(10)
  25. options = webdriver.ChromeOptions()
  26. options.add_argument('--headless')
  27. options.add_argument('--proxy-server=socks5://127.0.0.1:9050')
  28. options.add_argument('--disable-dev-shm-usage')
  29. options.add_argument('--no-sandbox')
  30. # options.add_argument('--remote-debugging-port=9222')
  31. # epath=os.environ['WEBDRIVER']
  32. options.add_experimental_option("debuggerAddress", "127.0.0.1:9922")
  33. # options.add_experimental_option("debuggerAddress", "192.168.192.45:9922")
  34. # options.add_experimental_option("debuggerAddress", q[2])
  35. # options.add_argument("--user-agent=" +user_agent)
  36. options.add_argument("--incognito")
  37. driver = webdriver.Chrome(executable_path=r'C:\portable\webdriver\chrome98\chromedriver.exe',options=options)
  38. # driver = webdriver.Chrome(executable_path=epath,options=options)
  39. driver.delete_all_cookies()
  40. driver.set_window_size(1400,1000)
  41. return driver
  42. print(q)
  43. process_query(q)
  44. driver=init_browser()
  45. #driver.get('https://www.youtube.com/watch?v=K5DEJXajtqA')
  46. driver.get('https://www.youtube.com/watch?v=_N0VneVhkoQ')
  47. video = driver.find_element_by_id('movie_player')
  48. video.send_keys(Keys.SPACE) #hits space
  49. time.sleep(1)
  50. video.click() #mouse click
  51. time.sleep(31)