pkk
pkk

Reputation: 379

unable to locate element , alt src image link

Trying to fetch the image link of channel icon image and banner image link from youtube but Unable to locate element.

refer the below image :

enter image description here

Code i have tried for channel icon image:

channel_icon = driver.find_element_by_xpath(
    "/html/body/ytd-app/div/ytd-page-manager/ytd-browse[2]/div["
    "3]/ytd-c4-tabbed-header-renderer/tp-yt-app-header-layout/div/tp-yt-app-header/div[2]/div[2]/div/div["
    "1]/yt-img-shadow/img").get_attribute("alt src")
print(channel_icon)

also it should work for every channel.

url for inspect -> https://www.youtube.com/c/FlyingBeast320/videos

Upvotes: 0

Views: 91

Answers (2)

You can try something like

channel_icon =  driver.find_element_by_xpath("//div[@id='channel-header-container']//img").get_attribute("src")
print(channel_icon)

banner_img = driver.find_element_by_xpath(
    '//ytd-c4-tabbed-header-renderer'
).get_attribute('style').split(
    '--yt-channel-banner:url('
)[1].split(');')[0].replace('\\', '')
print(banner_img)

Upvotes: 1

cruisepandey
cruisepandey

Reputation: 29362

You can use the below css selector :

div#channel-header-container img

in code :

channel_icon = driver.find_element_by_css_selector("div#channel-header-container img").get_attribute("src")
print(channel_icon)

Upvotes: 1

Related Questions