What is difference between strings and stripped_strings in BeautifulSoup
import requests
from bs4 import BeautifulSoup
url = "https://codewithharry.com"
r = requests.get(url)
htmlcontent = r.content
soup = BeautifulSoup(htmlcontent, 'html.parser')
tags = soup.find(id="imgpreview2")
# Using strings method
for item in tags.strings:
print(item)
# Using stripped_strings method
for item in tags.stripped_strings:
print(item)
Stripped Strings: it omits lines that consist of just empty spaces, and also removes leading and trailing spaces.
Strings: it does not omit lines with spaces or leading trailing space and contain \n etc.
Example:
Output: