c# - 在c#中捕获链接的rel类型和href

标签 c# parsing

我有一个字符串,其中应包含表单中的项目列表,{0}、{1} 和 {2} 是字符串,我基本上想提取它们。

我确实想针对 html 解析问题的一部分执行此操作,而且我听说用正则表达式解析 html 很糟糕。 (喜欢here)

我什至不确定如何使用正则表达式来做到这一点。

这是我得到的

string format = "<link rel=\".*\" type=\".*\" href=\".*\">";
Regex reg = new Regex(format);
MatchCollection matches = reg.Matches(input, 0);
foreach (Match match in matches)
 {
        string rel = string.Empty;
        string type = string.Empty;
        string href = string.Empty;
        //not sure what to do here to get these values for each from the match
 }

在我的研究发现我可能完全错误地使用正则表达式之前。

您将如何使用我选择的方法或使用 HTML 解析器来执行此操作?

最佳答案

使用 HTML 敏捷包库解析 HTML,可以找到 here

关于c# - 在c#中捕获链接的rel类型和href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1014534/

相关文章:

c# - 在 VS2010 中向后移植 .NET 4 到 3.5 SP1

c# - C# 上未处理的 AccessViolationException

C# 和 WPF 循环计数器值在调度程序中使用时不会改变

python pandas 解析带有月份名称的日期时间字符串

matlab - 如何判断 Matlab 代码在语法上是否有效?

django - 一个 BeautifulSoup 文档可以使用多个过滤器吗?

parsing - Haskell 中 Data.ByteString.Lazy.Char8 的解析器?

ios - Objective-C 附加字符串不起作用 NSXMLParser

c# - 在C#中创建没有只读属性的文件夹

c# - 将 DataGridView 的行复制到另一个 DataGridView