繁体   English   中英

如何从 python 中的字符串中删除某些 substring?

[英]how to remove certain substring from string in python?

a="<img src="hug.jpg/> India is a good country <img src="hug.jpg/> America is also good country "

所以我想这里是<img/>标签

In [104]: from bs4 import BeautifulSoup

In [105]: a="<img src=\"hug.jpg\"/> India is a good country <img src=\"hug.jpg\"/> America is also good country"

In [287]: soup = BeautifulSoup(a,"html.parser")

In [288]: soup.text
Out[288]: ' India is a good country  America is also good country'

In [289]: soup.text.strip()
Out[289]: 'India is a good country  America is also good country'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM