C# 正则求助
<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="undermark">+19,844</span>
</td>
</tr>
<tr>
<th>
保容量:
</th>
<td>
<span class="overermark">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="undermark">+8,677</span>
</td>
</tr>
<tr>
<th>
保容量:
</th>
<td>
<span class="overermark">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();
}
如果可以话通过这个方法里面的代码来获取。
[解决办法]
(?is)<tr>\s*<th>\s*前量:\s*</th>\s*<td>\s*<span[^>]*?class="undermark">\+(?<span>.*?)</span>\s*</td>\s*</tr>
简单点就这样 (?is)<span[^>]*?class="undermark">\+(?<span>.*?)</span>
[解决办法]
取Groups["span"].Value
这个方法private static String GetValueByRegex(String regex, String html)
regex参数传上面的正则就行了
[解决办法]
这是版主总结的帖子,非常有参考价值->
http://bbs.csdn.net/topics/380196757