Results 1 to 8 of 8

Thread: How to get the title of a web page?

  1. #1

    Thread Starter
    Banned
    Join Date
    Jan 2008
    Posts
    79

    How to get the title of a web page?

    Hot to get the title of a web HTML page, if the title is between <title> and </title> tags?
    Help me to get the text that is between these tags:

    <title>

    Title page here

    </title>

  2. #2
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: How to get the title of a web page?

    Hi AlexVorn,
    I think that this is not the proper forum to ask the question but if you use the command me.title in the code behind page it will return the page title like you want.
    Hope this helps
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  3. #3
    Lively Member
    Join Date
    Aug 2006
    Location
    india
    Posts
    88

    Re: How to get the title of a web page?

    cool tip c language wrong place for asp question

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: How to get the title of a web page?

    Use Regex

  5. #5

    Thread Starter
    Banned
    Join Date
    Jan 2008
    Posts
    79

    Re: How to get the title of a web page?

    @stanav, could u give some codes?

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: How to get the title of a web page?

    Quote Originally Posted by AlexVorn
    @stanav, could u give some codes?
    Sure... Try something like this
    Code:
    Dim html As String = "your html code goes here"
    Dim pattern As String = "(?<=\<title\>)[a-zA-Z0-9\s]*(?=\</title\>)"
    Dim m As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(html, pattern)
    Dim title As String = m.Value
    MessageBox.Show(title)

  7. #7
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: How to get the title of a web page?

    if you are navigating the webpage with a webbrowser, you can use Document.Title, eg:
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            wb.Navigate("http://www.google.co.uk")
        End Sub
    
        Private Sub wb_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wb.DocumentCompleted
            Console.WriteLine(wb.Document.Title)
        End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to get the title of a web page?

    You mentioned 'asp' but posted in the vb.net section, so I'll assume you're using ASP.NET rather than classic ASP.

    To get the title of a page, use HttpWebRequest's Response to read the page into a string, and then use stanav's code to find the title.

    If you want to get the title of the page you're currently on, use Page.Header.Title.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width