Beautiful Soup: Extract All Data Between Tags
Insurtech
.....Some data
Biometri
Solution 1:
s = '''<p>
<strong>
<em>
Insurtech
</em>
</strong>
</p>
<p> .....Some data </p>
<p>
<strong>
<em>
Biometrics
</em>
</strong>
</p>'''from bs4 import BeautifulSoup
soup = BeautifulSoup(html, 'html.parser')
>>> list(soup.stripped_strings)
['Insurtech', '.....Some data', 'Biometrics']
Solution 2:
You can use the .text
method to access the required info.
Ex:
s = """<p>
<strong>
<em>
Insurtech
</em>
</strong>
</p>
<p> .....Some data </p>
<p>
<strong>
<em>
Biometrics
</em>
</strong>
</p>"""from bs4 import BeautifulSoup
soup = BeautifulSoup(s, "html.parser")
html_tags = soup.find_all('p')
for h in html_tags:
print(h.text.strip()) #-->Update.
Output:
Insurtech
.....Some data
Biometrics
Post a Comment for "Beautiful Soup: Extract All Data Between Tags"