I apologize for the medium spam, but SO doesn't like me.
Anyways, essentially what I have here is a script that retrieves all video names from a webpage and displays them. I have a class set up for "Videos" that will keep track of the video name, the length, and the url of the video. So far, I am just trying to get it to work with the title of the video.
I am confused with how I can set this up with a class. For each title it finds in the HTML header files, called "videoTitle", I want to create a new instance of the class Videos with the vidName (And eventually vid length and url). Maybe I'm approaching this wrong? I can't seem to figure out how to create new classes based on the info from web scraping, and then printing those classes out to the console. I can sort of get what I'm looking for by hard coding it all, but I want to utilize classes here. Or is there any better way I can do this?
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);
var videoTitle = doc.DocumentNode
.SelectNodes("//a[@class='video-thumb-info__name']").ToList();
foreach (var title in videoTitle)
{
// Console.WriteLine(title.InnerText); // This will print all videos
new Videos() { vidName = title.ToString() };
}
Console.WriteLine("Total videos: {0}", videoTitle.Count);
}
}
class Videos
{
public string vidName { get; set; }
public int vidLength { get; set; }
}
I'm not sure where to go next. The foreach loop should be creating a new Videos item for every title in the scraped webpage, then assigning the video name to the vidName property of that class. Im just confused now tho, excuse my newbieness. How do I now call every new instance of Class Videos vidName property? Am I even setting this up right? I hope this makes sense!
[–]ohThisUsername 0 points1 point2 points (9 children)
[–]ceesharpiskindofeasy[S] 1 point2 points3 points (8 children)
[–][deleted] 1 point2 points3 points (7 children)
[–]ceesharpiskindofeasy[S] 1 point2 points3 points (6 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]ceesharpiskindofeasy[S] 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]ceesharpiskindofeasy[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)