BeautifulSoup एक python library है जो HTML और XML files से data निकालती है। BeautifulSoup का उपयोग करके, हम HTML या XML documents में मौजूद empty tags को भी remove कर सकते हैं और दिए गए data को human readable files में आगे convert कर सकते हैं।
पहले, हम अपने local environment में BeautifulSoup library को command का उपयोग करके install करेंगे: pip install beautifulsoup4
उदाहरण
# Import the BeautifulSoup library from bs4 import BeautifulSoup # Get the html document html_object = """Python is an interpreted, high-level and general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation.
""" # Let us create the soup for the given html document soup = BeautifulSoup(html_object, "lxml") # Iterate over each line of the document and extract the data for x in soup.find_all(): if len(x.get_text(strip=True)) == 0: x.extract() print(soup)
आउटपुट
उपरोक्त code चलाने से output generate होगा और दिए गए HTML document को human readable code में convert करेगा द्वारा empty tags को इसमें से remove करके।
<html><body><p>Python is an interpreted, high−level and general−purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation.</p> </body></html>