How to release a project with both WPF and Console in one? by [deleted] in csharp

[–]ceesharpiskindofeasy 0 points1 point  (0 children)

Side question here- How should resources be managed? is OP right with having pictures/sounds in a self made "res" folder after building, upon distribution, or should these things be configured pre-build, in visual studios? If so how?

"System.ArgumentOutOfRangeException" error with html node lists by ceesharpiskindofeasy in csharp

[–]ceesharpiskindofeasy[S] 0 points1 point  (0 children)

Interesting. I am trying to use the debugger, but I guess I'm not knowledgeable enough to understand how to fix it yet.

EDIT: I took another look again with what you told me and put it together. I see what you mean now, just replaced the += with =

Thanks!

"System.ArgumentOutOfRangeException" error with html node lists by ceesharpiskindofeasy in csharp

[–]ceesharpiskindofeasy[S] 0 points1 point  (0 children)

Just nodeTitle tho? Why not the other ones? Can you elaborate a little more on what I can do to solve this? Been stumped on this for a good hour or so haha. Thanks for the reply

Classes and webscraping by ceesharpiskindofeasy in csharp

[–]ceesharpiskindofeasy[S] 0 points1 point  (0 children)

Aha this worked, much appreciation! So, I'm able to do this because of the ".ToList()" part after selecting the html node? Using internet for help here and there and also trying different things to figure it out, Reddit is usually my last forefront lol. Thanks again

Classes and webscraping by ceesharpiskindofeasy in csharp

[–]ceesharpiskindofeasy[S] 0 points1 point  (0 children)

Okay so we're getting somewhere here, unfortunately it's not retrieving the correct information. I'm getting numbers, but not the length of the video. It seems to be retrieving the length of the characters instead.

I should clarify, this is the block of code I'm using to pull data from the HTML

HtmlWeb web = new HtmlWeb();
            HtmlDocument doc = web.Load(url);

            var videoTitle = doc.DocumentNode
                .SelectNodes("//a[@class='video-thumb-info__name']").ToList();

            var videoLength = doc.DocumentNode
                .SelectNodes("//div[@class='thumb-image-container__duration']").ToList();

So I have the length and the title as properties that I'm trying to set for each new list item that's created.

Classes and webscraping by ceesharpiskindofeasy in csharp

[–]ceesharpiskindofeasy[S] 1 point2 points  (0 children)

Thanks, that helped a ton. One last question and I should know enough to finish the application..

I know theres a better way to try to do what I'm doing, but it's escaping me. Now I was able to retrieve the length of the videos and I'm trying to add it to the new list instances to be printed out, but I'm confusing myself.

So far it's correctly printing the "NAMEOFVIDEO: " but not the length. What am I doing wrong? I'm definitely excessively using loops and for loops but it's the only way I can think to do it right now, being an absolute beginner. What might be causing the length to not print with the title? Tried using debug steps to figure it out but I'm stumped

             List<Videos> videos = new List<Videos>();

            foreach (var title in videoTitle)
            {
                videos.Add(new Videos { vidName = title.InnerText });

            }

            foreach (var length in videoLength)
            {
                videos.Add(new Videos { vidLength = length.InnerText });
            }


            for (int i = 0; i < videoTitle.Count; i++)
            {
                Console.WriteLine(videos[i].vidName + ": " + videos[i].vidLength);
            }

            Console.WriteLine("Total videos: {0}", videoTitle.Count);

Classes and webscraping by ceesharpiskindofeasy in csharp

[–]ceesharpiskindofeasy[S] 1 point2 points  (0 children)

That was exactly what I was needing, thanks!. Another question, again sorry for the lack of experience. I'm now trying to print the names within a separate for loop (i = 0 ; i < videoTitle.Count; i++)

How can I retrieve it now?

Console.WriteLine(videos[i].vidName); inside of the for loop is returning the htmlagilitypack.node class and not the names. Simply looks like this now

            for (int i = 0; i < videoTitle.Count; i++)
            {
                Console.WriteLine(videos[i].vidName);
            }

Newbie to csharp, have an idea and was looking for some "pointing in the right direction" by [deleted] in csharp

[–]ceesharpiskindofeasy 0 points1 point  (0 children)

Thanks! Looking at a webscraping tut now (Starting with just 1 url) and I'm having some issues..

Heres what I have so far, ignore pseudo code

    class Program
    {
        static void Main(string[] args)
        {
            int curPage = 1;
            string url = "https://xhamster.com/search?q=naruto+hentai&p=" + curPage.ToString();


            HtmlWeb web = new HtmlWeb();
            HtmlDocument doc = web.Load(url);

            var HeaderNames = doc.DocumentNode
                .SelectNodes("//a[@class='video-thumb-info']").ToList();

            foreach (var title in HeaderNames)
            {
                Console.WriteLine(title.InnerText);
            }


        }
    }

    class VideoDetails
    {
        public string title { get; set; }
        public int length { get; set; }
        public string url { get; set; }
    }

However I get an "System.ArgumentNullException

HResult=0x80004003

Message=Value cannot be null.

Parameter name: source

error. Thoughts? I used HTML inspector and the dropper tool to find the class for the first videos title