这段代码分析网页中的所有图片表单<img>,分析后为其前后添加相应的修饰标签,并添加到图片的超级链接。
- result = value.replace("","").replace(' ',u'')
- p=re.compile(r'''(<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*["']?[\s\t\r\n]*([^\s\t\r\n"'<>]*)[^<>]*?/?[\s\t\r\n]*>)''',re.IGNORECASE)
- result = p.sub(r'''<span class="openIcon"><em></em><a href="\2">\1</a></span>''',result)
来源: http://www.phpxs.com/code/1004840/