读书人

经BeautifulSoup处理html的后遗症怎么

发布时间: 2012-02-02 23:57:14 作者: rapoo

求助:经BeautifulSoup处理html的后遗症如何解决
用BeautifulSoup处理html之后,得到一个list,type一下发现该list和list中的每一个元素的类型分别是 BeautifulSoup.ResultSet 和 BeautifulSoup.NavigableString 。
请问如何才能将BeautifulSoup.NavigableString转换成普通的string,因为无法用string模块的函数处理NavigableString?谢谢!

运行如下:
>>>print type(soup)
<class 'BeautifulSoup.ResultSet'>
>>>print type(total) #total=soup[48]
<class 'BeautifulSoup.NavigableString'>
>>>filter(str.isdigit,total)
Traceback (most recent call last):
TypeError: descriptor 'isdigit' requires a 'str' object but received a 'unicode'

本人python新手,请行家帮助,谢谢!


[解决办法]
soup.text or str(soup)

读书人网 >perl python

热点推荐