I hope, I got your question right, here is an example:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.implicitly_wait(5)
# Let's create a list of terms to search for and an empty list for links
search_terms = ['Never Gonna Give You Up', 'Shrek']
links = []
for term in search_terms:
# Open YouTube page for each search term
driver.get('https://www.youtube.com/results?search_query={}'.format(term))
# Find a first webelement with video thumbnail on the page
link_webelement = driver.find_element(By.CSS_SELECTOR, 'div#contents ytd-item-section-renderer>div#contents a#thumbnail')
# Grab webelement's href, this is your link, and store in a list of links:
links += [link_webelement.get_attribute('href')]
print(links)
Hope this helps. Keep in mind, that for scraping data like this, you don't have to open webpages and use selenium, there are libraries like Beautiful Soup that help you do this kind of things faster.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…