-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyoutube_w_list.py
44 lines (36 loc) · 1.31 KB
/
youtube_w_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.common.exceptions import StaleElementReferenceException
import time
from selenium.webdriver.support.ui import WebDriverWait
#videos = ['hkaXd07-rTU','ldjtA3hj5cc','XSvBYVjgtGs']
videos = set()
f = open("vid.txt")
for p in f:
videos.add(p.strip())
prev = ""
for l in videos:
toget = "https://www.youtube.com/watch?v=" + l
print("toget",toget)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--public")
driver = webdriver.Chrome(ChromeDriverManager().install(),chrome_options=chrome_options)
for i in range(1,3):
try:
driver.get(toget)
driver.switch_to_window(driver.window_handles[0])
driver.refresh()
html = driver.execute_script("return document.getElementsByTagName('html')[0].innerHTML")
commas = str(html).split(",")
for line in commas:
if('dVideoId' in str(line)):
print(l,"||",line)
#print(html)
time.sleep(5)
driver.refresh()
driver.switch_to_window(driver.window_handles[1])
driver.refresh()
except:
continue
driver.close()