|  |      1zhzy      2020-03-08 00:20:27 +08:00 via iPhone 好奇“单一的好写但是全部的不成功”是什么情况😳 | 
|      2python30 OP | 
|  |      4PTLin      2020-03-08 00:37:10 +08:00 def foo(s):  template='<mip-img src="{0[0]}" alt="{0[1]}" ></mip-img>' m=re.match(r'.*src=\"(.*?)\"\s*alt=\"(.*?)\".*',s) if m is not None: return template.format(m.groups()) | 
|  |      5ysc3839      2020-03-08 06:26:13 +08:00 via Android 如果没有特殊限制,建议解析 html 再处理。 | 
|  |      6ClericPy      2020-03-08 11:47:40 +08:00 | 
|  |      8iRocW      2020-03-09 17:03:09 +08:00 只要提取 src alt 重写 不就好了? | 
|      9luckyc      2020-03-10 20:57:45 +08:00 ``` from bs4 import BeautifulSoup if __name__ == "__main__": html = """ <img src="http-url" alt="妹子" /> <img src="http-url" alt="妹子" style="height:auto !important;" /> <img src="http-url" alt="妹子" width="100%" /> """ soup = BeautifulSoup(html, 'html.parser') img = soup.find_all('img') for i in img: src = i.attrs['src'] alt = i.attrs['alt'] print(f'<mip-img src="{src}" alt="{alt}" ></mip-img>') ``` | 
|      10luckyc      2020-03-10 20:58:08 +08:00 为什么回复不支持 markdown? | 
|      11luckyc      2020-03-10 20:59:21 +08:00 |