【问题标题】:Use Regex to get text after /使用正则表达式在 / 之后获取文本
【发布时间】:2014-03-08 01:09:30
【问题描述】:

我有这个来自网站的文字

<a class='link--wrapper' href='/china/sights/architecture/old-buildings'>
<a class='link--wrapper' href='/china/sights/nature-wildlife/giant-panda-breeding-research-base'>

但我无法使用 re.findall 仅在 / 之后捕获文本 到目前为止我能做的最好的就是

Link = re.findall("(?<=sights/).*(?='>)", Webpage)

返回

architecture/old-buildings
nature-wildlife/giant-panda-breeding-research-base

我想要返回的是

old-buildings
giant-panda-breeding-research-base

【问题讨论】:

    标签: python regex python-3.x


    【解决方案1】:

    您的正则表达式包含斜线。使用这个:

    /sights/.+/([^/']+)'
    

    【讨论】:

      【解决方案2】:

      试试这个:

      "(?<=sights\/.+\/).+(?='>)"
      

      【讨论】:

        猜你喜欢
        • 2021-03-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-27
        相关资源
        最近更新 更多