Failing To Get Duration Of Youtube Video Using Xpath
I wanted to write something that would return me the video duration of a youtube link. So I found requests and lxml and started out following this guide. Here's the setup: import r
Solution 1:
span[@class="ytp-time-duration"]
this span
tag is generated by JavaScript, and it will not returned by requests
, requests
just return the HTML code
Solution 2:
For YouTube the Xpath was not consistent. I got two different Xpaths (these are the 2 Xpaths I got for capturing the Video Duration)
//*[@id='movie_player']/div[5]/div/div/div[5]/button/div[1]
//*[@id="movie_player"]/div[26]/div[2]/div[1]/div/span[3]
Tried the option of finding the Element by Class name
FindElement(By.ClassName("ytp-time-duration"))
This worked always.
string VideoDuration = firfxdrivr.FindElement(By.ClassName("ytp-time-duration")).GetAttribute("textContent");
Console.WriteLine(VideoDuration);
Output: 19:18
Post a Comment for "Failing To Get Duration Of Youtube Video Using Xpath"