110,538
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
string html=@"";
MatchCollection mc = Regex.Matches(html, @"<td>(?<t>\d{2}:\d{2})</td>\s+<td><b>(?<vs>[^<]+)</b></td>\s+<td>(?<y>[.\d]+)</strong>");
foreach (Match m in mc)
{
Console.WriteLine(m.Groups["t"].Value);
Console.WriteLine(m.Groups["vs"].Value);
Console.WriteLine(m.Groups["y"].Value);
Console.WriteLine("=====================");
}
}
string result = "";
string html = @"<caption>11年04月01日</caption>
<tr><th rowspan='2' width='50'>联赛</th>
<th rowspan='2' width='50'>时间</th>
<th rowspan='2'>比赛对阵</th>
<th colspan='3' width='190'>亚洲盘口</th>
<th colspan='3' width='105'>全场标盘</th>
<th colspan='3' width='105'>上半场标盘</th>
<th colspan='3' width='105'>大小球</th>
<th rowspan='2' width='40'>比<br/>分</th>
<th rowspan='2' width='40'>盘<br/>路</th>
<th rowspan='2' width='40'>变<br/>盘</th></tr>
<tr><th width='45'><em>贴水</em></th><th width='100'><em>让球</em></th><th width='45'><em>贴水</em></th>
<th width='35'><em>胜</em></th><th width='35'><em>平</em></th><th width='35'><em>负</em></th>
<th width='35'><em>胜</em></th><th width='35'><em>平</em></th><th width='35'><em>负</em></th>
<th width='35'><em>大</em></th><th width='35'><em>界限</em></th><th width='35'><em>小</em></th></tr>
<tr><td style='background-color:#006633'><strong style='color:#FFFFFF'>巴杯</strong></td>
<td>06:30</td>
<td><b>邦迪比达vs戈亚斯</b></td>
<td>1.77</strong> </td><td>平手/半球 </td><td>1.99</strong> </td><td>1.95</strong> </td><td>3.25</strong> </td><td>3.37</strong> </td><td>2.65 </td><td>2.05 </td><td>3.75 </td><td>1.7 </td><td>2.5 </td><td>2 </td>
<td>0-3</td><td><a href='list.php?id=128127' target='_blank'>盘路</a></td>
<td><a href='javascript:void(0);oc_menu('hiddendata_1')'><img src='images/aopan_hz_011.gif' width='29' height='19' alt=''/></a> </td>
</tr>
<tbody id='hiddendata_1' style='display:none;'>
<tr><td colspan='2' rowspan='3'> </td><td>04-01 04:00</td><td><strong style='color:#006600;'>1.77</strong> </td><td>平手/半球 </td><td><strong style='color:#006600;'>1.99</strong> </td><td><strong style='color:#006600;'>1.95</strong> </td><td><strong style='color:#006600;'>3.25</strong> </td><td><strong style='color:#FF0000;'>3.37</strong> </td><td>2.65 </td><td>2.05 </td><td>3.75 </td><td>1.7 </td><td>-</td><td>2 </td><td colspan='3' rowspan='3'><a href='javascript:void(0);oc_menu('hiddendata_1')'><img src='images/aopan_hz_014.gif' width='95' height='21' alt=''/></a></td></tr><td>03-31 21:10</td><td><strong style='color:#FF0000;'>1.77</strong> </td><td>平手/半球 </td><td><strong style='color:#006600;'>1.99</strong> </td><td>2.05 </td><td>3.25 </td><td>3.1 </td><td> </td><td> </td><td> </td><td> </td><td>-</td><td> </td></tr><td>03-29 21:30</td><td>1.75 </td><td>平手/半球 </td><td>2.01 </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>-</td><td> </td></tr>
</tbody> <tr><td style='background-color:#006633'><strong style='color:#FFFFFF'>巴杯</strong></td>
<td>[07:00</td>
<td><b>普丹迪vs明尼路</b></td>
<td>1.84</strong> </td><td>受半球/一球 </td><td>1.92</strong> </td><td>4.45</strong> </td><td>3.5</strong> </td><td>1.65</strong> </td><td>3.65 </td><td>2.15 </td><td>2.5 </td><td>1.7 </td><td>2.75 </td><td>2 </td>
<td>2-1</td><td><a href='list.php?id=128116' target='_blank'>盘路</a></td>
<td><a href='javascript:void(0);oc_menu('hiddendata_2')'><img src='images/aopan_hz_011.gif' width='29' height='19' alt=''/></a> </td>
</tr>";
string pattern = @"<td.*?>(.*?)</td>\s*<td.*?><b>(.*?)</b></td>\s*<td>(.*?)</strong>.*?</td><td.*?>(.*?) </td><td.*?>(.*?)</strong>.*?</td><td.*?>(.*?)</strong>.*?</td><td.*?>(.*?)</strong>.*?</td><td.*?>(.*?)</strong>.*?</td><td.*?>(.*?).*?</td><td.*?>(.*?) </td><td.*?>(.*?) </td><td.*?>(.*?) </td><td.*?>(.*?) </td><td.*?>(.*?) </td>";
MatchCollection mc = Regex.Matches(html, pattern, RegexOptions.IgnoreCase);
for (int i = 0; i < mc.Count; i++)
{
for (int j = 1; j < mc[i].Groups.Count; j++)
{
result += mc[i].Groups[j].Value + " ";
}
result += "\r\n";
}
//result就是最后的结果
static void Main(string[] args)
{
string html=@"";
MatchCollection mc = Regex.Matches(html, @"<td>\[?(?<t>\d{2}:\d{2})</td>\s+<td><b>(?<vs>[^<]+)</b></td>\s+<td>(?<y>[.\d]+)</strong>");
foreach (Match m in mc)
{
Console.WriteLine(m.Groups["t"].Value);
Console.WriteLine(m.Groups["vs"].Value);
Console.WriteLine(m.Groups["y"].Value);
Console.WriteLine("=====================");
}
}