BeautifulSoup(raw_html 1


# Extracting raw html from locally saved html file using BeautifulSoup

from bs4 import BeautifulSoup
url = r"C:\example.html"
soup = BeautifulSoup(url, "html.parser")
text = soup.get_text()
print (text)

Here is what the above code is Doing:
1. We import the BeautifulSoup class creator from the package bs4.
2. We open the file using the open() function and assign it to a variable.
3. We pass the variable to the BeautifulSoup() function and assign it to a new variable.
4. We use the get_text() function to extract the text without html tags.
5. We print the text.

Similar Posts