Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this code but it does not seem to be displaying the tittle on label2 when an input such as "https://www.google.com" is taken from the user in textBox1. I am using a windows forms application.

What I have tried:

string title = Regex.Match(textBox1.Text, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
            label2.Text = title;
Posted
Updated 10-Oct-21 7:58am
Comments
Richard Deeming 11-Oct-21 5:08am    
You're now even further from the correct answer than you were last week!
Getting the tittle of a webpage from URL.[^]
candijen 11-Oct-21 12:12pm    
what?
Richard Deeming 11-Oct-21 12:17pm    
In last week's question, you took the URL entered by the user, made a web request to load the content of that URL, and tried to extract the title from it.

In this version, you're trying to extract the <title> element directly from the URL string, which doesn't contain the <title> element.

Solution 1 has given you the correct answer. But it's the same answer you were given last week, when you were actually closer to the answer.
candijen 11-Oct-21 13:18pm    
huh well I managed to get it tho.

1 solution

The only way to get the title of a website is to fetch the page and extract the text in the title tag.

This should help: Html Agility pack | Html Agility Pack[^] - it can read a site from a URL, and extract the title in a couple of lines of code.
 
Share this answer
 

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