正则表达式找不到匹配项

2024-09-28 22:19:34 发布

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

我对使用regex还比较陌生,正在尝试查找以下文本:

<div class="name">

    <a href="/rd/?S=1401191307481569663391991831690328817&I=&DS=42639&T=55&U=http%3A%2F%2Fwww.spokeo.com%2Fmapview%2Fperson%2F18643819031%3Fpx%3D%26piplstart%3D%26q%3DJoe%2BHenderson%2C%2BPhoenix%2C%2BAZ%26g%3Dname_piplv2_scd_city01&P=">
        <span class="highlight"> … </span>

         T 

        <span class="highlight"> … </span>

        , E Flower St, 

        <span class="highlight"> … </span>

        , 

        <span class="highlight"> … </span>

        , 

        <span class="highlight"> … </span>

        , 50 years old

    </a>

</div>
<div class="url">

    www.spokeo.com/mapview/person/18643819031?px=&piplstart=&q=Joe+Hend...

</div>

我想到的表达方式是:

("<div class=\"name\">[\S\s]+</div><div class=\"url\">[\S\s]+</div>") 

但是没有找到匹配项。感谢您的帮助。你知道吗


Tags: name文本divurldsrdclassregex
1条回答
网友
1楼 · 发布于 2024-09-28 22:19:34

这里有一条新线:

</div>
<div class="url">

但你的正则表达式中没有:

         |
         V
...</div><div...

尝试在那里添加\s*(假设\s在Python中包含新行,div实际上总是紧跟在一起,中间只有空格)。你知道吗

但是,如前所述,using regex to parse HTML is playing with fire。你知道吗

相关问题 更多 >