I am using javascript to get the links from a webpage like this:
function GetTheLinks()
{
var linksArray = [];
for(var i = 0; i < document.links.length; i++)
{
var link = document.links[i];
linksArray.push( link.innerHTML );
linksArray.push( link.innerText );
linksArray.push( link.href );
}
return linksArray;
}
This works fine.
I would alike to retrieve the image urls associated with the links in a YT page. Because I didn't find any documentation about it, I have just added this to my code:
linksArray.push( link.img );
This however didn't work.
How could I get the image associated with a link?
The element for a YT link looks like this:
<img id="img" class="style-scope yt-img-shadow" alt="" width="168" src="https://i.ytimg.com/vi/qPityOntlS4/hqdefault.jpg?sqp=-oaymwEbCKgBEF5IVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLAQZFtofXXUlC1Ra5EPzJopddMcow">
The selector just says:
#img
XPath:
//*[@id="img"]
Full XPath:
/html/body/ytd-app/div[1]/ytd-page-manager/ytd-watch-flexy/div[5]/div[2]/div/div[3]/ytd-watch-next-secondary-results-renderer/div[2]/ytd-item-section-renderer/div[3]/ytd-compact-video-renderer[2]/div[1]/ytd-thumbnail/a/yt-img-shadow/img
Thank you!