python re模块_已解决
本帖最后由 涛4091 于 2023-2-23 11:04 编辑import re
a = '''
<div class='tory'><span id='5'>名字</span></div>
'''
obj = re.compile(r"<div class='.*?'><span id='.*?'>(?<name>.*?)</span></div>",re.S)
result = obj.finditer(a)
for it in result:
print(it.group(name))
报错了 你要检索哪些数据 a = '''
<div class='tory'><span id='5'>名字</span></div>
'''
obj = re.compile(
r"<div class='.*?'><span id='.*?'>(?P<name>.*?)</span></div>", re.S)
result = obj.finditer(a)
for it in result:
print(it.group('name')) 两处问题
1.标记格式为(?P<xxx>)
2.group(xxx),参数是字符串,很像字典的索引 大马强 发表于 2021-8-3 11:35
两处问题
1.标记格式为(?P)
2.group(xxx),参数是字符串,很像字典的索引
好,谢了
页:
[1]