-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_videos.py
More file actions
41 lines (26 loc) · 1.26 KB
/
Copy pathget_videos.py
File metadata and controls
41 lines (26 loc) · 1.26 KB
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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
def get_videos(url):
options = webdriver.ChromeOptions()
options.headless = True
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
driver.set_window_size(600, 700)
videos = []
driver.get(url)
button = driver.find_element(By.CSS_SELECTOR, "button.VfPpkd-LgbsSe")
button.click();
title = driver.title
#assert title == "Fireship - YouTube"
driver.implicitly_wait(1)
content = driver.find_element(By.ID, 'content').find_elements(By.CSS_SELECTOR, 'ytd-rich-grid-row')
for video in content:
data = video.find_element(By.ID, 'content').find_element(By.CSS_SELECTOR, "*").find_element(By.ID, "dismissible").find_element(By.ID, 'details').find_element(By.ID, 'meta').find_element(By.CSS_SELECTOR, 'h3').find_element(By.CSS_SELECTOR, 'a')
title = data.get_attribute('title')
link = data.get_attribute('href')
videos.append([title, link])
driver.quit()
return videos
if __name__ == '__main__':
get_videos("https://www.youtube.com/@Fireship/videos")