I would also use HtmlAgilityPack
if i had to parse HTML. You can use SelectSingleNode
, GetAttributeValue
and string methods to create a dictionary of key- and value pairs:
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html));
var anchor = doc.DocumentNode.SelectSingleNode("a");
string href = anchor.GetAttributeValue("href", "");
// take the text between both $
int startIndex = href.IndexOf('$') + 1;
href = href.Substring(startIndex, href.Length - startIndex);
Dictionary<string, string> pageInfos = href.Split(';')
.Select(token => token.Split('='))
.ToDictionary(kv => kv[0].Trim(), kv => kv[1].Trim(), StringComparer.InvariantCultureIgnoreCase);
string id = pageInfos["id"]; // c828c4ea-075d-4dde-84f0-1876f8b71fa8
string type = pageInfos["type"]; // FlexiPage