BeautifulSoup (bs4) is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree, making web scraping simple and fast.
Installation:
pip install beautifulsoup4
Key Features:
- Parse HTML and XML documents effortlessly
- Navigate parse trees using tag names, attributes, and CSS selectors
- Handles poorly formatted HTML (malformed markup) automatically
- Convert incoming documents to Unicode and outgoing documents to UTF-8
Code Example:
from bs4 import BeautifulSoup
html_doc = "<html><head><title>Python Scraping</title></head><body><p class='content'>Hello World</p></body></html>"
soup = BeautifulSoup(html_doc, 'html.parser')
print("Title:", soup.title.string)
print("Paragraph:", soup.find('p', class_='content').text)
No comments:
Post a Comment