Click here to Skip to main content
15,886,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to scrape titles of movies from a site. in foreach when i use
messagebox.show(item.InnerText);
it works and it shows the titles but first it won't open the windows form and second it shows a lot of messages.

the code ( i want to make this application in windows form ):

public Form1()
        {
            InitializeComponent();
            

            HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
            HtmlAgilityPack.HtmlDocument doc = web.Load("https://yts.mx/");
            foreach (var item in doc.DocumentNode.SelectNodes("//a[@class='browse-movie-title']"))
            {
                label1.Show(item.InnerText);
            }

        }


What I have tried:

i tired this code:
label1.Show(item.InnerText);
it said "no overload for method show takes 1 arguments"
i don't understand this, what does it mean and what should i do to make titles show in like 10-15 labels instead of 10 message boxes?
Posted
Updated 30-Jun-21 7:08am
Comments
[no name] 30-Jun-21 15:52pm    
Too much "noise" for a constructor; should be using a Window / Form Loaded event; async task; etc.

If you do not understand an issue with a .NET control then you should first check the documentation: Control.Show Method (System.Windows.Forms) | Microsoft Docs[^].
 
Share this answer
 
Read up on the documentation for the Label control.

You change the text a label shows by setting it's Text property to a string.

You would normally NEVER call Show() on a label.
 
Share this answer
 
Comments
brandon1999 30-Jun-21 13:28pm    
thank you, i replaced the code with label1.Text = item.InnerText;
but now the problem is that, the code above gets 16 titles and this code only shows 1.
is it possible to make 16 labels that show all the 16 different titles? if yes, how can i do it?
Dave Kreskowiak 30-Jun-21 13:30pm    
That's the wrong way to think about this. You have a single string that contains more than what you're expecting. You have to figure out what all that content really is and possibly come up with a method to get what you need and not all the extra junk.
brandon1999 30-Jun-21 13:34pm    
the code only gets titles and i want all the titles. i'm looking at htmlagilitypack documentation but there's only two codes, i can either get all of them at once, or i can get only the first title!
Dave Kreskowiak 30-Jun-21 13:35pm    
You are getting a single string with all the content. Again, you have to parse that up to get what you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900