Diese Methode gibt eine List<string> aller Links aus dem übergebenen HTML Quelltext zurück.
benötigte Usings:
using System.Collections.Generic;
using System.Text.RegularExpressions;
/// <summary>
/// Gets the HTML links.
/// </summary>
/// <param name="html">The HTML.</param>
/// <returns></returns>
private List<string> GetHtmlLinks(string html)
{
string linkPattern = "<a href=\"(.*?)\">(.*?)</a>";
MatchCollection linkMatches = Regex.Matches(html, linkPattern, RegexOptions.Singleline);
List<string> linkContents = new List<string>();
foreach (Match match in linkMatches)
linkContents.Add(match.Value);
return linkContents;
}
6 Kommentare zum Snippet