NavigableString class – Python Beautifulsoup
Last Updated :
25 Oct, 2020
NavigableString class is provided by Beautiful Soup which is a web scraping framework for Python. Web scraping is the process of extracting data from the website using automated tools to make the process faster. A string corresponds to a bit of text within a tag. Beautiful Soup uses the NavigableString class to contain these bits of text.
Syntax:
<tag> String here </tag>
Below given examples explain the concept of NavigableString class in Beautiful Soup.
Example 1: In this example, we are going to see the type of a string.
Python3
from bs4 import BeautifulSoup
soup = BeautifulSoup(
, "lxml" )
tag = soup.h2
string = tag.string
print ( type (string))
|
Output:
<class 'bs4.element.NavigableString'>
Example 2: In this example we are going to convert the NavigableString to a Unicode string.
Python3
from bs4 import BeautifulSoup
soup = BeautifulSoup(
, "lxml" )
tag = soup.h2
string = str (tag.string)
print ( type (string))
|
Output:
<type 'str'>
Share your thoughts in the comments
Please Login to comment...