簡體   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