将 NavigableString 转换为 unicode 字符串

xra*_*alf 2 python string unicode beautifulsoup

当我运行以下代码时:

if substr in movie.lowercase:

我收到以下错误

AttributeError: 'NavigableString' object has no attribute 'lowercase'

movie 来自这里:

movie = row.td.div.h4.string

我试图将其更改为(没有成功)

movie = row.td.div.h4.string.string

或者

movie = unicode(row.td.div.h4.string)

您知道如何使用lowercase方法将 NavigableString 转换为普通的 unicode 字符串吗?

jfs*_*jfs 5

unicode()没有.lowercase()它有的方法.lower()

NavigableString是 的一个实例unicode。它有所有的unicode方法。

不区分大小写的搜索.lower()比在 Python 中调用例如完整的 unicode casefolding(不区分大小写的关键字搜索)更复杂