37,719
社区成员
发帖
与我相关
我的任务
分享
原文
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 这样的一组链接
但不知道如何获取 “要获取的文字” 这一组数据
拜谢
多谢亲,,,感激不尽
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']