请教正则高手 取06:30/邦迪比达vs戈亚斯/1.77 等,注意这种纪录会有很多

小D2013 2011-04-24 12:21:44
<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>
...全文
101 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
小D2013 2011-04-25
  • 打赏
  • 举报
回复
我用你的代码测试没问题,但是沾到我的程序里就不行了,应该是我的问题,结贴
小D2013 2011-04-25
  • 打赏
  • 举报
回复
风云,你这个我试了,之前的也试了,出不来,你有邮箱吗?帮我看看好吗
sunny906 2011-04-25
  • 打赏
  • 举报
回复
你把我的代码完全复制一份,result怎么会没有结果呢?
sxldfang 2011-04-25
  • 打赏
  • 举报
回复
帮你给个测试字符串吧:

string html=@"
...
<td>01:00</td>
<td><b>马德里竞技vs勒万特</b></td>
<td>1.98</strong> </td><td>一球 </td><td>1.88</strong> </td><td>1.45</strong> </td><td>3.9</strong> </td><td>6.1</strong> </td><td>2.1 </td><td>2.2 </td><td>4.85 </td><td>2.2 </td><td>3 </td><td>1.6 </td>

<td>4-1</td><td><a href=""list.php?id=121270"" 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=""11""> </td><td>04-25 01:10</td><td><strong style=""color:#FF0000;"">1.98</strong> </td><td>一球 </td><td><strong style=""color:#006600;"">1.88</strong> </td>
<td>01:00</td>
<td><b>沙兰迪兵工厂vs甘拿斯亚</b></td>
<td>2.22</strong> </td><td>半球 </td><td>1.6</strong> </td><td>2.1</strong> </td><td>3.22</strong> </td><td>3.03</strong> </td><td>2.75 </td><td>1.9 </td><td>3.95 </td><td>1.9 </td><td>2.25 </td><td>1.8 </td>

<td>1-1</td><td><a href=""list.php?id=125187"" 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>
<tbody id=""hiddendata_2"" style=""display:none;"">
<tr><td colspan=""2"" rowspan=""4""> </td><td>04-25 00:50</td><td><strong style=""color:#FF0000;"">2.22</strong> </td><td>半球 </td><td><strong style=""color:#006600;"">1.6</strong> </td><td><strong style=""color:#FF0000;"">2.1</strong> </td><td><strong style=""color:#006600;"">3.22</strong> </td><td><strong style=""color:#006600;"">3.03</strong> </td><td>2.75 </td><td>1.9 </td><td>3.95 </td><td>1.9 </td><td>-</td><td>1.8 </td><td colspan=""3"" rowspan=""4""><a href=""javascript:void(0);oc_menu('hiddendata_2')""><img src=""images/aopan_hz_014.gif"" width=""95"" height=""21"" alt=""""/></a></td></tr><td>04-24 22:00</td><td><strong style=""color:#FF0000;"">2.17</strong> </td><td>半球 </td><td><strong style=""color:#006600;"">1.65</strong> </td><td><strong style=""color:#FF0000;"">2</strong> </td><td><strong style=""color:#006600;"">3.22</strong> </td><td><strong style=""color:#006600;"">3.26</strong> </td><td> </td><td> </td><td> </td><td> </td><td>-</td><td> </td></tr><td>04-24 21:30</td><td><strong style=""color:#FF0000;"">2.07</strong> </td><td>半球 </td><td><strong style=""color:#006600;"">1.75</strong> </td><td>1.95 </td><td>3.22 </td><td>3.4 </td><td> </td><td> </td><td> </td><td> </td><td>-</td><td> </td></tr><td>04-21 18:00</td><td>2.02 </td><td>半球 </td><td>1.8 </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:#348017""><strong style=""color:#FFFFFF"">墨超</strong></td>
<td>01:00</td>
<td><b>莫雷利亚vs堤格雷斯</b></td>
<td>2.01</strong> </td><td>平手/半球 </td><td>1.75</strong> </td><td>2 </td><td>3.2 </td><td>3.22 </td><td>2.65 </td><td>2.05 </td><td>3.65 </td><td>1.95 </td><td>2.5 </td><td>1.75 </td>

<td>0-3</td><td><a href=""list.php?id=125608"" target=""_blank"">盘路</a></td>
<td><a href=""javascript:void(0);oc_menu('hiddendata_3')""><img src=""images/aopan_hz_011.gif"" width=""29"" height=""19"" alt=""""/></a> </td>
</tr>
<tbody id=""hiddendata_3"" style=""display:none;"">
<tr><td colspan=""2"" rowspan=""2""> </td><td>04-25 00:40</td><td><strong style=""color:#006600;"">2.01</strong> </td><td>平手/半球<img src=""http://odds.sports.sina.com.cn/odds/images/li_02.gif"" width=""12"" height=""12"" alt=""""/> </td><td><strong style=""color:#FF0000;"">1.75</strong> </td><td>2 </td><td>3.2 </td><td>3.22 </td><td>2.65 </td><td>2.05 </td><td>3.65 </td><td>1.95 </td><td>-</td><td>1.75 </td><td colspan=""3"" rowspan=""2""><a href=""javascript:void(0);oc_menu('hiddendata_3')""><img src=""images/aopan_hz_014.gif"" width=""95"" height=""21"" alt=""""/></a></td></tr><td>04-23 17:10</td><td>2.06 </td><td>半球 </td><td>1.7 </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:#348017""><strong style=""color:#FFFFFF"">墨超</strong></td>
<td>01:00</td>
<td><b>托卢卡vs达高斯</b></td>
<td>1.64</strong> </td><td>半球/一球 </td><td>2.12</strong> </td><td>1.52 </td><td>3.5 </td><td>5.55 </td><td>2.05 </td><td>2.2 </td><td>5 </td><td>1.7 </td><td>2.5 </td><td>2 </td>
.....
"

内容太多,粘贴不进来!
sxldfang 2011-04-25
  • 打赏
  • 举报
回复
虽然你的数据有点小错,但我2楼的已经可以正常工作(楼主没试?)

根据你的网址,又进行简单修改,效果良好



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("=====================");
}
}
小D2013 2011-04-25
  • 打赏
  • 举报
回复
sunny906, 验证不通过 ,show出来没有东西
sunny906 2011-04-25
  • 打赏
  • 举报
回复

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就是最后的结果
小D2013 2011-04-24
  • 打赏
  • 举报
回复
http://odds.sports.sina.com.cn/odds/

我想抓取上面这个地址显示出的历史数据,保存包本地
  • 打赏
  • 举报
回复
我好像以前是 用xml读取出来的,你这用表格读取的,好麻烦哦!

在说,你查找的话,直接拼接sql语句不行吗???
sxldfang 2011-04-24
  • 打赏
  • 举报
回复
你的数据好像有问题:

试一下这个:


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("=====================");
}
}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧