如何从Python中的字符串中删除某些子字符串?

时间:2020-07-31 13:40:42

标签: python python-3.x string substring

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

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

1 个答案:

答案 0 :(得分:1)

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'