【求助】正则匹配 提取文字

jzdriver 2021-06-09 21:29:08

原文

item=   

        # <a href="thread-0000-1-1.html" style="font-weight: bold;color: purple">要提取的文字1</a>
        # <a href="thread-0000-1-4.html" style="color: purple">要提取的文字2</a>
        # <a href="thread-0000-1-2.html" style="font-weight: bold;color: blue">要提取的文字3</a>
        # <a href="thread-0000-1-4.html" style="font-weight: bold;color: green">要提取的文字4</a>
        # <a href="thread-0000-1-4.html" style="font-weight: bold;color: red">要提取的文字5</a>
        # <a href="thread-0000-1-7.html" style="color: blue">要提取的文字6</a>

通过  

link = re.findall(re.compile(r'<a href="(.*?)"'), item)[0]   

正确的获得了 thread-0000-1-1.html 这样的一组链接

 

但不知道如何获取 “要获取的文字”  这一组数据

 

拜谢

 

...全文
865 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jzdriver 2021-07-07
  • 打赏
  • 举报
回复

多谢亲,,,感激不尽

rrrr336 2021-06-13
  • 打赏
  • 举报
回复
import re
item = \
 '''# <a href="thread-0000-1-1.html" style="font-weight: bold;color: purple">要提取文字1</a>
    # <a href="thread-0000-1-4.html" style="color: purple">要提取的文字2</a>
    # <a href="thread-0000-1-2.html" style="font-weight: bold;color: blue">要提取文字3</a>
    # <a href="thread-0000-1-4.html" style="font-weight: bold;color: green">要提取文字4</a>
    # <a href="thread-0000-1-4.html" style="font-weight: bold;color: red">要提取文字5</a>
    # <a href="thread-0000-1-7.html" style="color: blue">要提取文字6</a>'''
rx = r'(?<=>).+(?=</a>)'
content = re.findall(rx, item)
print(content)
# ['要提取文字1', '要提取的文字2', '要提取文字3', '要提取文字4', '要提取文字5', '要提取文字6']

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧