一段html代码如下在<h1>美国</h1>加利福尼亚州,“赫拉”有“很多”的意思,<h1>该州发起的此项<span style="color:red;">请愿</span>活动</h1>,希望把这个词变成一个国际公认的、为既百万(mega)、kilo 和十亿(giga)之后的又一个“后缀”。想通过.net实现的要求是获取第二个<h1>之间的内容,即 “该州发起的此项<span style="color:red;">请愿</span>活动”请问这个正值该怎么写呢?int TitleS = result.IndexOf("<h1>") + 4;
int TitleE = result.IndexOf("</h1>", TitleS);
string Title = result.Substring(TitleS, TitleE - TitleS);只能获取第一个的
int TitleE = result.IndexOf("</h1>", TitleS);
string Title = result.Substring(TitleS, TitleE - TitleS);只能获取第一个的
int TitleE = result.IndexOf(" </h1>", TitleS);
string result = result.Substring(TitleS, TitleE - TitleS);
TitleS = result.IndexOf(" <h1>") + 4;
TitleE = result.IndexOf(" </h1>", TitleS);
string Title = result.Substring(TitleS, TitleE - TitleS);
Regex r = new Regex(@"(?is)(?<= <h1>)(?:(?!</?/h1\b).)*(?=</h1>)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
foreach (Match m in r.Matches(strs))
{
foreach (Capture c in m.Captures)
{
string str = c.Value;
}
}
Regex r = new Regex(@"(?is)(?<= <h1>)(?:(?!</?/h1\b).)*(?=</h1>)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
foreach (Match m in r.Matches(strs))
{
foreach (Capture c in m.Captures)
{
string str = c.Value;
}
}
int count = strs.Length;
int starIndex = strs.IndexOf(", <h1>", 0, count);
int endIndex = strs.IndexOf("</h1>", starIndex, count - starIndex);
string str = strs.Substring(starIndex+6, endIndex - starIndex-6);
var val = xEle.Elements("h1");
return val.ElementAt<XElement>(1).Value;