BeautifulSoup: Can't convert NavigableString to string

后端 未结 4 1217
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 06:51

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

4条回答
  •  感情败类
    2021-01-18 07:31

    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..

提交回复
热议问题