【发布时间】:2013-12-16 14:39:34
【问题描述】:
我有一个要求,我只需要从此 HTML 获取链接
"<span class=""name""><a href=Details.aspx?entityID=1&hash=20&searchFunctionID=53b&type=Advanced&nameSet=Entities&q=a&textSearchType=ExactPhrase&orgTypes=01%2c02%2c03%2c04%2c05%2c06%2c07%2c08%2c09%2c10%2c11%2c12%2c13%2c14%2c15%2c16%2c90%2c96%2c98%2c99> GOOGLE CORPORATION </a> </span> <br /> <span class=typeDescription> 09 - Analytics Company </span>"
我需要的输出是
Details.aspx?entityID=1&hash=20&searchFunctionID=53b&type=Advanced&nameSet=Entities&q=a&textSearchType=ExactPhrase&orgTypes=01%2c02%2c03%2c04%2c05%2c06%2c07%2c08%2c09%2c10%2c11%2c12%2c13%2c14%2c15%2c16%2c90%2c96%2c98%2c99
我用过
string sPattern ="[<a href=](.*?(99))";
MatchCollection mcMatches = Regex.Matches(input,sPattern);
foreach (Match m in mcMatches)
{
Console.WriteLine(m.Value);
}
这没有给我正确的输出。谁能指出我正确的方向。
【问题讨论】:
-
用正则表达式解析 HTML? Bad idea! 相反,为什么不使用适当的 HTML 解析器,例如 Html Agility Pack?
-
请不要使用 RegEx 解析 HTML。