匹配端口号

2024-04-20 13:17:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试匹配来自html页面的<span>标记中的端口号:

<span class="tbBottomLine" style="width:50px;">
                8080
        </span>
<span class = "tbBottomLine" style = "width: 50px;">
            80
    </ span>
<span class = "tbBottomLine" style = "width: 50px;">
            3124
    </ span>
<span class = "tbBottomLine" style = "width: 50px;">
            1142
    </ span>

脚本:

^{pr2}$

但我得到的输出是:

['8', '8', '0', '0', '0', '8', '8', '0', '0', '8', '8', '8', '8', '8', '8', '8', '8', '0']

我需要它来匹配8080例如。在


Tags: 标记脚本stylehtml页面widthclassspan
2条回答

您正在重复组([0-9]){2,}。用最后一个值覆盖。在

相反,在小组内部重复子模式:

<span[^>]*>\s*([0-9]{2,})\s*</\s*span>

编码

^{pr2}$

如果你想把端口从页面上拉下来。在

parser_port = '<span.*>\s*([0-9]{2,})+\s*</span>'

您需要一个或多个长度至少为两个的字符({2,})。但是仍然不清楚用例是什么。在

相关问题 更多 >