How to retrieve the title of a web page

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

In a Windows Forms application I want to get the title of a web page
when I know it's url. For example, the page which the url
"http://groups.google.com/" refers has the title "Google Groups". How
do I return "Google Groups" when I know only the url? Thanks.
 
Mike,

If you don't have the page in a browser already, then you will have to
download the content from the page. You can use the HttpWebRequest and
HttpWebResponse classes to get the content. Once you have the content, you
will have to parse the HTML and get the contents of the <title> tag, which
is what is displayed in the browser title bar.

Hope this helps.
 
It's right.
May be RegEx will help you to parse the page :-)
Something like this:
<(?<title>\b\w+\b)[^>]*>(?<text>.*?)</\k<\/title>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top