【发布时间】:2016-11-16 16:36:27
【问题描述】:
我在 django 中有应用程序,我必须以特定方式显示文本。
这是我的html代码:
<p class="name">
<b>Name of person</b> City, Country</p>
<p class="name">
<b>Name of person</b></p>
我想在普通文本中加粗人名和城市和国家,例如:
**Name of person** City, Country
**Name of person**
但是我只能得到b,我怎样才能得到p里面的所有p和b?
我在 BeautifulSoap 中的代码:
people = self.concattexts.filter(code='Active')
for p in people:
soup = BeautifulSoup(p.text_html, 'html.parser')
all_people = [b.get_text(separator=' - ', strip=True) for b in soup.find_all('b')]
return all_people
【问题讨论】:
标签: python regex django beautifulsoup