I\'m starting to learn Python and I\'ve decided to code a simple scraper. One problem I\'m encountering is I cannot convert a NavigableString to a regular string.
U
For Python 3, the answer is merely
str(tag.string)
Other answers will fail.
unicode()
is not a built-in in Python 3.
tag.string.encode('utf-8')
will convert the string to a byte string, which you don't want..
I came up to this question and got it solved best by the answer of Mark Ramson from How to remove this \xa0 from a string in python? with
import unidecode
word = unidecode.unidecode(tag.string)
You can do this:
unicode(tag.string)
I tried to decode when I should have encoded:
str(child.encode('utf-8'))