As you have the HtmlAgilityPack already, you can extract the "title" attribute like this:
Option Infer On
Option Strict On
Imports HtmlAgilityPack
Module Module1
Sub Main()
Dim a = "<a href=""/tothepage"" title=""the page"">The Link</a>."
Dim doc As New HtmlDocument()
doc.LoadHtml(a)
Dim node = doc.DocumentNode.SelectSingleNode("/a")
Dim title = node?.Attributes("title")?.Value
Console.WriteLine(title) ' outputs "the page"
Console.ReadLine()
End Sub
End Module
Of course, you won't need that many lines of code as that is a complete working example.
The ?.
parts prevent it from throwing an error if node
is Nothing (in this case if there wasn't an "<a>" element) and prevent it from throwing an error if there is no "title" attribute.
With a regular expression, the group will contain it ([^"]*)
:
title="([^"]*)"
C#
using System.Text.RegularExpressions;
static void Main(string[] args)
{
string originalString = "<a href=\" / tothepage\" title=\"the page\">The Link</a>.";
Regex rgx = new Regex("title=\"([^\"]*)\"", RegexOptions.IgnoreCase);
Match match = rgx.Matches(originalString)[0];
Console.WriteLine(match.Groups[1]);
Console.ReadLine();
}