xxxxxxxxxx
from bs4 import BeautifulSoup
# HTML document
html_doc = """
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p class="content">This is a paragraph.</p>
<a href="https://www.example.com" class="link">Example Website</a>
</body>
</html>
"""
# Create a Beautiful Soup object
soup = BeautifulSoup(html_doc, 'html.parser')
# Find an element and get its attribute value
link_element = soup.find('a')
attribute_value = link_element['href']
print(attribute_value)
xxxxxxxxxx
from bs4 import BeautifulSoup
# Assuming we have an HTML document stored in the variable 'html_doc'
# Create a BeautifulSoup object
soup = BeautifulSoup(html_doc, 'html.parser')
# Find all elements with a specific tag that have a particular attribute
elements = soup.find_all('tag_name', attrs={'attribute_name': 'attribute_value'})
# Loop through the elements and print their attribute values
for element in elements:
attribute_value = element['attribute_name']
print(attribute_value)