Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get text from div which contains b tag with text

from bs4 import BeautifulSoup

raw_text = """<div style="margin: 0 0 15px 0;">
                <b>Description</b><br>
                Dryer is not working. Please have someone take a look at it
            </div>"""
soup = BeautifulSoup(raw_text,"html.parser")
work_order_no = soup.find("b",text="Description")
print(work_order_no)
add= work_order_no.next_sibling
print(add.text)

Required_solution : Dryer is not working. Please have someone take a look at it

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In your HTML code, work_order_no.next_sibling refers to the element that comes after <b>Description</b>, and that is <br>. You need to find the next element after that. To do this, try:

add= work_order_no.next_sibling.next_sibling
print(add.text)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading