parser02.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.support.ui import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. import time
  7. import sys
  8. url = sys.argv[1]
  9. driver = webdriver.Firefox()
  10. driver.get(url)
  11. time.sleep(7)
  12. try:
  13. element = driver.find_element(By.XPATH, """html/body/c-wiz/div/div/div/div[2]/div[1]/div[3]/div[1]/form[2]/div/div/button""")
  14. element.click()
  15. except:
  16. element = driver.find_element(By.XPATH, """/html/body/ytd-app/ytd-consent-bump-v2-lightbox/tp-yt-paper-dialog/div[4]/div/div[6]/div[1]/ytd-button-renderer[2]""")
  17. element.click()
  18. time.sleep(10)
  19. try:
  20. element = driver.find_element(By.XPATH, """/html/body/ytd-app/div[1]/ytd-page-manager/ytd-watch-flexy/div[5]/div[1]/div/div[6]/div[1]/div[2]/ytd-video-primary-info-rinfo-renderer/div/div/div[3]/div/ytd-menu-renderer/yt-icon-button/button/yt-icon""")
  21. element.click()
  22. time.sleep(5)
  23. except:
  24. element = driver.find_element(By.CSS_SELECTOR, """ytd-menu-renderer.ytd-video-primary-info-renderer > yt-icon-button:nth-child(3) > button:nth-child(1)""")
  25. element.click()
  26. time.sleep(5)
  27. element = driver.find_element(By.XPATH, """/html/body/ytd-app/ytd-popup-container/tp-yt-iron-dropdown/div/ytd-menu-popup-renderer/tp-yt-paper-listbox/ytd-menu-service-item-renderer/tp-yt-paper-item""")
  28. element.click()
  29. time.sleep(10)
  30. try:
  31. element = driver.find_element(By.XPATH, """/html/body/ytd-app/div[1]/ytd-page-manager/ytd-watch-flexy/div[5]/div[1]/div/div[2]/ytd-engagement-panel-section-list-renderer[4]/div[2]/ytd-transcript-renderer/div[2]/ytd-transcript-search-panel-renderer/div[2]/ytd-transcript-segment-list-renderer""")
  32. print(element.text)
  33. text = element.text
  34. z = open('test.txt', 'w')
  35. z.write(text)
  36. z.close
  37. g = open('prov.txt', 'w')
  38. g.write("sss")
  39. g.close
  40. except:
  41. print("111")