37,720
社区成员
发帖
与我相关
我的任务
分享
(?![\s\S]*?class="c2")<a href="([^"]+)"
(?![\s\S]*?class="c2")<a href="([^"]+)"
#-*-coding:utf-8-*-
import re
txt='''
<html>
<body>
<div class="inner">
<dl class="c1">
<dd><a href="1.html">1</a></dd>
<dd><a href="2.html">2</a></dd>
</dl>
<dl class="c2">
<dd><a href="3.html">2</a></dd>
<dd><a href="4.html">4</a></dd>
</dl>
</div>
</body>
</html>
'''
patt1=re.compile(r'class="c2"(.*?)</dl>',re.S)
patt2=re.compile(r'<a href="(.*?)">',re.S)
results=patt1.findall(txt)
for res in results:
tmpHREF=patt2.findall(res)
for href in tmpHREF:
print href