from bs4 import BeautifulSoup html_doc = """Sample title Author name
Article subject
""" soup = BeautifulSoup(html_doc, 'html.parser') print(soup.prettify())
from bs4 import BeautifulSoup html_doc = """Sample title Author name
Article subject
""" soup = BeautifulSoup(html_doc, 'html.parser') author_tag = soup.find('p', {'class': 'author'}) print(author_tag)
from bs4 import BeautifulSoup html_doc = """""" soup = BeautifulSoup(html_doc, 'html.parser') ul_tag = soup.ul for li_tag in ul_tag.find_all('li'): a_tag = li_tag.a print(a_tag['href']) This code navigates the HTML tree structure to find all `li` tags within the `ul` tag and prints the value of the href attribute of the associated `a` tag. In conclusion, BeautifulSoup is a powerful package for web scraping and handling HTML/XML data in Python. It provides a wide range of functionalities to extract and manipulate data from web pages.Sample title Main heading
Author name
Article subject