Trouble displaying links using python selenium

sampss s

I'm trying to display a list of links that I parsed, it displays 1, when deriving a variable linkvideo2 I get the result in the form of the first link to the video. Maybe you can't use CSS_SELECTOR with a loop?)

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as EC

import time 

name = 'hello world'
profile_path = r"C:/Users/Федорчик/Desktop"
options=Options()
options.set_preference('profile', profile_path)
driver = webdriver.Firefox(options=options)
#driver = webdriver.Firefox(r"C:/Users/Федорчик/Desktop")
driver.get('https://www.youtube.com')
id_serth = driver.find_element(By.NAME, "search_query")
id_serth.send_keys(name)
button_serth = driver.find_element(By.ID, "search-icon-legacy")
time.sleep(4)
button_serth.click()
time.sleep(4)
button_filtr = driver.find_element(By.CLASS_NAME ,"ytd-toggle-button-renderer")
button_filtr.click()
time.sleep(4)
button_filtrtode=driver.find_element(By.CLASS_NAME, "ytd-search-filter-renderer")
button_filtrtode.click()
time.sleep(4)

urltek = driver.current_url


linkvideo2 = driver.find_elements(By.CSS_SELECTOR, 'ytd-video-renderer.style-scope:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > h3:nth-child(1) > a:nth-child(2)')
links=[]
for i in linkvideo2:
    links.append(i.get_attribute('href'))
print(len(links))

print (urltek)

Answer:

1
https://www.youtube.com/results?search_query=hello+world&sp=EgIIAQ%253D%253D

I will be very grateful for your help

Tim Ing

better find by ID

linkvideo2 = driver.find_elements(By.ID, 'video-title')
links=[]
for i in linkvideo2:
    links.append(i.get_attribute('href'))
print(len(links))

print(urltek)
print(links)

output of "links" will be something like this:

[None, None, None, None, None, 'https://www.youtube.com/shorts/uXMjlXBW_fg', 'https://www.youtube.com/watch?v=s0a7AWgo6CY', 'https://www.youtube.com/watch?v=SEgOG1fZwoM', 'https://www.youtube.com/watch?v=XXFdprzIxvc', 'https://www.youtube.com/watch?v=82YAs_viROM', 'https://www.youtube.com/watch?v=IgRObNaGhAg', 'https://www.youtube.com/watch?v=sFLPNXJU4KY', 'https://www.youtube.com/watch?v=64Wo6zQDgQ0', 'https://www.youtube.com/watch?v=SpvI9648RrU', 'https://www.youtube.com/watch?v=wUw-rh97fso', 'https://www.youtube.com/watch?v=C7XDmQsf1-A', 'https://www.youtube.com/watch?v=3md7eviZC_Y', 'https://www.youtube.com/watch?v=wklkXDhb6MQ', 'https://www.youtube.com/watch?v=82wxikm2CwI', 'https://www.youtube.com/watch?v=D1DVUYcE43A', 'https://www.youtube.com/watch?v=MvFgCJqpxWI', 'https://www.youtube.com/shorts/8cfy5DjIS10', 'https://www.youtube.com/watch?v=5RV3unTmyTA', 'https://www.youtube.com/watch?v=Sjgee-HCCxs', 'https://www.youtube.com/watch?v=vUGQsCQNUgs']

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Trouble connecting to phantomJs webdriver using python and selenium

Trouble scraping reviews using Selenium in Python

Having trouble finding an element using Selenium/Python

Trouble clicking button using Selenium with Python

Trouble saving file uploaded using Python Selenium

Trouble getting attributes of elements using Selenium | Python

Trouble Navigating To the Next Page Using Python Selenium

Fetch only specific links using selenium in python

Click all links of table using Selenium Python

having trouble scraping results (links,dates) from a SEC page while using selenium

Python selenium not displaying text

Having trouble finding/searching for links and saving them to a list variable through python/selenium

Trouble selecting from Google Dropdown menu using Selenium (Python)

Web scrapping using selenium in python, trouble in click the button

Trouble finding a element on myanimelist.net using selenium package in python

Having trouble displaying JSON objects using Angular

Get links from a certain div using Selenium in Python

How to get all fb profile links using selenium and python

Unable to locate the pagination links when scraping a website using Selenium and Python

Click and scrape 'a href' links by class name using Selenium in Python

How to Pull Links from Google Search using Selenium, Python

Unable to print foodpanda product links using selenium python

Using Selenium+python to extract HTML code from a list of links

How to scrape all links of products using selenium python?

Trouble with pyplot displaying resized images in python

Trouble with Selenium Python related Imports

Trouble clicking on different links using puppeteer

Trouble creating real NTFS links using Cygwin

Displaying image as links using php and mysql