use*_*054 5 html python beautifulsoup abbr
我需要将外部源生成的数百个html句子转换为可读文本,并且我对abbr标记的转换有疑问。下面是一个示例:
from bs4 import BeautifulSoup
text = "<abbr title=\"World Health Organization\" style=\"color:blue\">WHO</abbr> is a specialized agency of the <abbr title=\"United Nations\" style=\"color:#CCCC00\">UN</abbr>."
print (BeautifulSoup(text).get_text())
Run Code Online (Sandbox Code Playgroud)
该代码返回“ WHO是联合国的专门机构”。。但是,我想要的是“ WHO(世界卫生组织)是联合国(联合国)的专门机构”。有没有办法做到这一点?也许是另一个模块,而不是BeautifulSoup?