对正则表达式解析HTML(在C#) [英] regex for html parsing (in c#)
本文介绍了对正则表达式解析HTML(在C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图解析HTML页面,并从表行中提取2值。
的HTML表行如下: -
I'm trying to parse a html page and extract 2 values from a table row. The html for the table row is as follows: -
<tr>
<td title="Associated temperature in (ºC)" class="TABLEDATACELL" nowrap="nowrap" align="Left" colspan="1" rowspan="1">Max Temperature (ºC)</td>
<td class="TABLEDATACELLNOTT" nowrap="nowrap" align="Center" colspan="1" rowspan="1">6</td>
<td class="TABLEDATACELLNOTT" nowrap="nowrap" align="Center" colspan="1" rowspan="1"> 13:41:30</td>
</tr>
和表达我此刻的:
<tr>[\s]<td[^<]+?>Max Temperature[\w\s]*</td>[\s]
<td[^<]+?>(?<value>([\d]+))</td>[\s]
<td[^<]+?>(?<time>([\d\:]+))</td>[\s]</tr>
不过,我似乎不能够提取任何匹配。
任何人都可以点我在正确的方向,谢谢。
However I don't seem to be able to extract any matches. Could anyone point me in the right direction, thanks.
推荐答案
尝试
<tr>\s*
<td[^>]*>.*?</td>\s*
<td[^>]*>\s*(?<value>\d+)\s*</td>\s*
<td[^>]*>\s*(?<time>\d{2}:\d{2}:\d{2})\s*</td>\s*
</tr>\s*
这篇关于对正则表达式解析HTML(在C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文