http://ent.qq.com/star/shouye2012/gangtai.htm
我只要要从这个网站上面获取这四块的所有内容,请大家帮忙正则表达式怎么写呀???我只要正则表达式,,求帮助呀,用正则表达式怎么写呀???行业数据C#正则表达式
我只要要从这个网站上面获取这四块的所有内容,请大家帮忙正则表达式怎么写呀???我只要正则表达式,,求帮助呀,用正则表达式怎么写呀???行业数据C#正则表达式
调试欢乐多
加个去贪婪,免得多匹配
Regex Content = new Regex(@"<div[^>]*>[\s\S]*?src="(?<pic>[^"]*)"\s*alt="(?<title>[^"]*)">[\s\S]*?<span\s*class="date">(?<date>[^<]*)</span>[\s\S]*?", RegexOptions.IgnoreCase | RegexOptions.Multiline);
System.Text.RegularExpressions.MatchCollection ct = Content.Matches(htmlCode);
int count = 0;
foreach (Match m in ct)
{
mode n = new mode();
if (ct[count].Groups["src"].Value!="")
{
richTextBox1.AppendText = Clear.GetKeyName(m.Groups["src"].Value+ "\r\n");
}
}
我代码是这样写的可是筛选不到呀
string tempStr="";//源文本
string pattern = @"(?i)<div[^>]*>[\s\S]*?src="(?<pic>[^"]*)"\s*alt="(?<title>[^"]*)">[\s\S]*?<span\s*class="date">(?<date>[^<]*)</span>[\s\S]*?<div[^>]*>(?<all>[^<]*)<";
Match m = Regex.Match(tempStr,pattern);
string value1 = m.Groups["pic"].Value;
string value2 = m.Groups["title"].Value;
string value3 = m.Groups["date"].Value;
string value4 = m.Groups["all"].Value;
string pattern = @"(?i)<div[^>]*>[\s\S]*?src=""(?<pic>[^""]*)""\s*alt=""(?<title>[^""]*)"">[\s\S]*?<span\s*class=""date"">(?<date>[^<]*)</span>[\s\S]*?<div[^>]*>(?<all>[^<]*?)<";
string htmlCode = richTextBox2.Text;
Regex Content = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
System.Text.RegularExpressions.MatchCollection ct = Content.Matches(htmlCode);
foreach (Match m in ct)
{
mode n = new mode();
richTextBox1.AppendText(Clear.GetKeyName(m.Groups["title"].Value + "\r\n"));
}运行结果如图
为什么第一条标题“组图:46岁周慧敏现身显气质 露黄牙显不雅”获取不到呢