/// summary
/// 获取Html字符串中指定标签的指定属性的值
/// /summary
/// param name=htmlHtml字符/param
/// param name=tag指定标签名/param
/// param name=attr指定属性名/param
/// returns/returns
private Liststring GetHtmlAttr(string html, string tag, string attr)
{
Regex re = new Regex(@( + tag + @[\w\W].+?));
MatchCollection imgreg = re.Matches(html);
Liststring m_Attributes = new Liststring();
Regex attrReg = new Regex(@([a-zA-Z1-9_-]+)\s*=\s*(\x27|\x22)([^\x27\x22]*)(\x27|\x22), RegexOptions.IgnoreCase);
for (int i = 0; i imgreg.Count; i++)
{
MatchCollection matchs = attrReg.Matches(imgreg[i].ToString());
for (int j = 0; j matchs.Count; j++)
{
GroupCollection groups = matchs[j].Groups;
if (attr.ToUpper() == groups[1].Value.ToUpper())
{
m_Attributes.Add(groups[3].Value);
break;
}
}
}
return m_Attributes;
}
给你粘贴一个方法,我也是在网上找到的。具体地址已经不清楚了。
取消
评论