Solution: Python beautiful soup parse string that has only closing br tag

Development | Programming languages
Author
Description
I have problem extracting address.
<div class="practice-location"><strong>Primary Location of Practice</strong>
<br/>Suite 100<br/>2010 Eglinton Avenue West<br/>Toronto ONA A M6E 2K3<br/><strong> </div>
I want a string to look like
Suite 1002010 Eglinton Avenue WestToronto ONA A M6E 2K3
Attachments
No attachments.
Solutions
from bs4 import BeautifulSoup

html="""<div class="practice-location"><strong>Primary Location of Practice</strong>
<br/>Suite 100<br/>2010 Eglinton Avenue West<br/>Toronto ONA A M6E 2K3<br/><strong>
</div>"""

soup = BeautifulSoup(html, 'html.parser')
dt = soup.find(class_ ={"practice-location"})
# remove "strong" here
dt.strong.extract()

# print all html field
print(dt)

# print string tag
print(dt.strong.extract())

# print practice-location print(dt.text.strip())

on November 28th, 2018 (9:52 pm)
What masters said
You must sign in to comment!!
All comments
This solution has not been commented yet.