【发布时间】:2016-02-24 21:08:48
【问题描述】:
<tr>
11:15
12:15
13:15
</tr>
<tr>
18:15
19:15
20:15
</tr>
in this case output should be: [ (11:15, 12:15, 13:15), (18:15, 19:15, 20:15) ]
我的模式:(\d\d:\d\d)[\s\S]*?(\d\d:\d\d)[\s\S]*?(\d\d:\d\d)[\s\S]*?</tr>
仅当每个 tr 标签中有 3 小时时才有效
但是如果每个 tr 标签中有 1-3 小时(格式相同 \d\d:\d\d),这应该可以工作。 另一个例子。为此,我的模式不再适用。
<tr>12:00 13:00</tr>
<tr>14:00 15:00 16:00</tr>
<tr>12:00</tr>
Output should be: [ (12:00, 13:00, ), (14:00, 15:00, 16:00), (12:00, , ) ]
还有一件事:每个小时不只是由空格分隔,真正的文件看起来像这样:
我为此使用了[\s\S]*? or [\w\s<>="-/:;?|]*?。一个小时要么是简单的跨度,要么是更长的形式
.
示例:
<tr>
<span class="na">16:00</span>
<span>|</span><a href="http:/21.28.147.68/msi/default.aspx?event_id=52514&typetran=1&ReturnLink=http://www.kino.pl/kina/przedwiosnie/repertuar.php" class="toolBox" data-hasqtip="true" aria-describedby="qtip-0">20:45</td>
</tr>
【问题讨论】:
-
别告诉我你是using regex to parse html。
-
[\s\S]不等于.吗? -
[\s\S]匹配任何内容,包括 newline ,而.不匹配。 -
@user1858268 除非你使用
re.DOTALL作为标志。 -
对于现实生活中的例子,您不应该这样做:
re.findall('\d\d:\d\d', target_source)吗?