All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
asp.net得到HTML,meta标记的内容_[Asp.Net教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/1/30 1:21:37 Browse times: 378 Comment times: 0

asp.net得到HTML,meta标记的内容_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

asp.net得到HTML meta标记的内容_[Asp.Net教程] public static string GetSingleTagValueByAttr(string inputstring, string tagName, string attrname, string key)
{
Regex reg = new Regex("<" + tagName + " [^<>]*>", RegexOptions.IgnoreCase);
MatchCollection matchs = reg.Matches(inputstring);
string result = string.Empty;
foreach (Match match in matchs)
{
string matchValue = match.Value;
Regex regValue = new Regex("content=".*"", RegexOptions.IgnoreCase);
if (matchValue.ToLower().IndexOf(attrname.ToLower() + "="" + key.ToLower() + """) != -1)
{
if (regValue.IsMatch(matchValue))
{
result = regValue.Match(matchValue).Value;
if (!string.IsNullOrEmpty(result))
{
result = result.Replace("CONTENT=", "").Replace("content=","").Replace(""", "");
}
}
return result;
}
}
return null;
}


使用举例:

获取关键词 GetSingleTagValueByAttr(data, "meta", "name", "Keywords"); data是HTML源代码
获取描述GetSingleTagValueByAttr(data, "meta", "name", "Discription");

来源:http://blog.csdn.net/slimboy123





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.