<div class="t_Tooltip t_Tooltip_cloud t_hidden" style="left: -10000px; top: -10000px;
z-index: 999999; transition-duration: 220ms; display: block; width: 140px; height: 110px;">
<div class="t_Shadow" style="top: 0px; left: 0px; width: 140px; height: 110px;">
<div class="t_ShadowBubble" style="width: 140px; height: 110px;">
<canvas width="280" height="220" style="width: 140px; height: 110px;"></canvas>
</div>
</div>
<div class="t_Skin" style="width: 136px; height: 105px; top: 3px; left: 2px;">
<div class="t_Bubble" style="width: 136px; height: 105px; top: 0px; left: 0px;">
<canvas width="272" height="210" style="width: 136px; height: 105px;"></canvas>
</div>
</div>
<div class="t_Content" style="left: 3px; top: 11px; width: 100%;">
<div class="t_ContentContainer t_clearfix t_Content_cloud" style="width: auto; height: auto;">
<div style="" class="htmlTooltip">
<h1>
金屬</h1>
<div class="splitLine">
</div>
<table class="resourceTooltip">
<tbody>
<tr>
<th>
現有量:
</th>
<td>
<span class="">3,293,129</span>
</td>
</tr>
<tr>
<th>
儲存容量:
</th>
<td>
<span class="">33,005,000</span>
</td>
</tr>
<tr>
<th>
當前產量:
</th>
<td>
<span class="under">+19,844</span>
</td>
</tr>
<tr>
<th>
保護倉容量:
</th>
<td>
<span class="overer">0</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="t_Tooltip t_Tooltip_cloud t_hidden" style="left: -10000px; top: -10000px;
z-index: 999999; transition-duration: 220ms; display: block; width: 133px; height: 110px;">
<div class="t_Shadow" style="top: 0px; left: 0px; width: 133px; height: 110px;">
<div class="t_ShadowBubble" style="width: 133px; height: 110px;">
<canvas width="266" height="220" style="width: 133px; height: 110px;"></canvas>
</div>
</div>
<div class="t_Skin" style="width: 129px; height: 105px; top: 3px; left: 2px;">
<div class="t_Bubble" style="width: 129px; height: 105px; top: 0px; left: 0px;">
<canvas width="258" height="210" style="width: 129px; height: 105px;"></canvas>
</div>
</div>
<div class="t_Content" style="left: 3px; top: 11px; width: 100%;">
<div class="t_ContentContainer t_clearfix t_Content_cloud" style="width: auto; height: auto;">
<div style="" class="htmlTooltip">
<h1>
晶體</h1>
<div class="splitLine">
</div>
<table class="resourceTooltip">
<tbody>
<tr>
<th>
現有量:
</th>
<td>
<span class="">1,396,821</span>
</td>
</tr>
<tr>
<th>
儲存容量:
</th>
<td>
<span class="">5,355,000</span>
</td>
</tr>
<tr>
<th>
當前產量:
</th>
<td>
<span class="under">+8,677</span>
</td>
</tr>
<tr>
<th>
保護倉容量:
</th>
<td>
<span class="overer">0</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
上面是两段结构一样的代码。
我希望【分别】获取到
第一段里面的:19,844
和
第二段里面的:8,677
private static String GetValueByRegex(String regex, String html)
{
var reg = new Regex(regex, RegexOptions.Singleline | RegexOptions.IgnoreCase); var value = reg.Match(html).Groups[1].Value; return value.Trim();
}
如果可以话通过这个方法里面的代码来获取。
这是版主总结的帖子,非常有参考价值->
http://bbs.csdn.net/topics/380196757
{
List<String> list=new List<String>();
var reg = new Regex(regex, RegexOptions.Singleline | RegexOptions.IgnoreCase);
foreach(var m in reg.Matches(html))
{
list.Add(m.Groups["span"].Value);
}
return list;
}调用 GetValueByRegex(@"(?is)<span[^>]*?class=""under"">\+(?<span>.*?)</span>",html);
foreach(var m in reg.Matches(html))
{
list.Add(m.Groups["span"].Value);
}
没有 Groups 属性