0

I'm trying to get the watch urls of all uploaded videos in the video manager on YouTube. How do I select all videos on the page? I figured that the class name vm-video-title-content yt-uix-sessionlink exists in the a tag on every video but how can it be used to retrieve all of the href attributes? I'm struggling with the selector.

This is the html snippet I'm basically dealing with:

<a href="/watch?v=THE_WATCH_ID" class="vm-video-title-content yt-uix-sessionlink" data-sessionlink="THE_SESSION_LINK_ID_OR_SOMETHING">THE_VIDEO_TITLE</a>

In Selenium I tried doing

By videoSelector = By.className("vm-video-title-content.yt-uix-sessionlink");
List<WebElement> webElements = webDriver.findElements(videoSelector);
System.out.println(webElements.size());

but it prints a size of 0.

Note that I placed a dot in the class name since compound class names are not supported.

Is my approach promising or is there a better way of doing it?

Community
  • 1
  • 1
BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185

1 Answers1

0

I think you misunderstood "classes", and how they work in HTML.

Your HTML sample specifies two classes: vm-video-title-content and yt-uix-sessionlink. Note that this is a space-separated list!

Your Java code is asking for a completely different one class: vm-video-title-content.yt-uix-sessionlink. Note that is done by exact string comparison!

If you try something like:

By videoSelector = By.className("vm-video-title-content");

You should be little closer to what you want.

SiKing
  • 10,003
  • 10
  • 39
  • 90
  • Alright, but I still get 0 results. How can that be if the class exists? – BullyWiiPlaza Jun 26 '15 at 18:08
  • Might be worth pointing out, that Google go out of their way, a lot, to prevent people from automating / scraping their site. – SiKing Jun 26 '15 at 18:13
  • I don't think that anything would prevent a knowledgeable individual to do whatever it desires to automate so I'm hoping somebody can help me out with this task since it obviously isn't "impossible" – BullyWiiPlaza Jun 26 '15 at 18:16