A very long clean paragraph
A very long dark paragraph
A very long paragraph without attribute
A very long light paragraph
”’
soup = BeautifulSoup(html_content, ‘html.parser’)
no_class_attribute = soup.find(“p”, attrs={“class”: None})
print(no_class_attribute)
# Output:
A very long paragraph without attribute
“>A very long clean paragraph
A very long dark paragraph
A very long paragraph without attribute
A very long light paragraph
”’
soup = BeautifulSoup(html_content, ‘html.parser’)
no_class_attribute = soup.find(“p”, attrs={“class”: None})
print(no_class_attribute)
# Output:
A very long paragraph without attribute
“>A very long clean paragraph
A very long dark paragraph
A very long paragraph without attribute
A very long light paragraph
”’
soup = BeautifulSoup(html_content, ‘html.parser’)
no_class_attribute = soup.find(“p”, attrs={“class”: None})
print(no_class_attribute)
# Output:
A very long paragraph without attribute
“>
To find elements without a specific attribute using BeautifulSoup, we use the attrs parameter of the function find, and we specify the attributes as None.
For example, to find the paragraph element without a class name, we set attrs={"class": None}:
import requests
from bs4 import BeautifulSoup
html_content = '''
A very long clean paragraph
A very long dark paragraph
A very long paragraph without attribute
A very long light paragraph
'''
soup = BeautifulSoup(html_content, 'html.parser')
no_class_attribute = soup.find("p", attrs={"class": None})
print(no_class_attribute)
# Output: A very long paragraph without attribute
