Answer the question
In order to leave comments, you need to log in
How to make a non unicode string?
beautifulsoup documentation - https://www.crummy.com/software/BeautifulSoup/bs4/...
we can decode a NavigableString into a regular unicode string, which NavigableString is not.
Visually, they do not differ
type(soup.h1.text)
>>>class 'str'
type(soup.h1.string)
>>>class 'bs4.element.NavigableString'
Answer the question
In order to leave comments, you need to log in
Just create a new class that accepts a string like
class CustomStr:
def __init__(self, str_):
self.__str = str_
def d_space(self):
return "".join(self.__str.split())
Didn't wash anything. Here:
soup = BeautifulSoup(html,"html.parser")
var = soup.title.string
print(var)
print(type(var))
In var there will be just NavigableString:Hello World! Site Title
<class 'bs4.element.NavigableString'>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question