如果tag中包含多个字符串,可以使用.strings来循环获取:for string in soup.strings: print(repr(string)) # u"The Dormouse's story" # u'\n\n' # u"The Dormouse's story" # u'\n\n' # u'Once upon a time there we ...
Tag,NavigableString,BeautifulSoup几乎覆盖了html和xml中的所有内容,但是还有一些特殊对象.容易让人担心的内容是文档的注释部分:markup = "b!--Hey, buddy. Want to buy a used parser?--/b" soup = BeautifulSoup( ...
下面的一段HTML代码将作为例子被多次用到.这是爱丽丝梦游仙境的的一段内容(以后内容中简称为爱丽丝的文档):html_doc = """ htmlheadtitleThe Dormouse's story/title/head body p class="title"bThe Dormouse's stor ...