-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwbc1.py
35 lines (29 loc) · 958 Bytes
/
wbc1.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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
co = webdriver.ChromeOptions()
co.add_argument("--incognito")
co.add_argument("--window-size=1920,1080")
driver = webdriver.Chrome(options=co)
start_url = "https://www.youtube.com/watch?v=mJ-qvsxPHpY"
links = set()
def crawl(start_link):
driver.get(start_link)
#driver.page_source?
elements = driver.find_elements_by_tag_name('a')
urls_to_visit = set()
for el in elements:
urls_to_visit.add(el.get_attribute('href'))
for el in urls_to_visit:
if start_url in el and el not in links:
links.add(el)
crawl(el)
# Call the function with the starting URL
crawl(start_url)
# Print the collected links
print("Collected links:")
for link in links:
print(link)
# Close the Chrome driver
driver.close()
# at the end of script wait for user to supply input, delaying script exit
#raw_input("Press Enter to exit")