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>
Printable View
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>
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
cool tip c language wrong place for asp question
Use Regex
@stanav, could u give some codes?
Sure... Try something like thisQuote:
Originally Posted by AlexVorn
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)
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
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.