【发布时间】:2011-07-14 20:25:03
【问题描述】:
我正在尝试从这种格式的网站中提取数据
<div id=storytextp class=storytextp align=center style='padding:10px;'>
<div id=storytext class=storytext>
<div class='a2a_kit a2a_default_style' style='float:right;margin-left:10px;border:none;'>
..... extra stuff
</div> **Main Content**
</div>
</div>
注意 MainContent 可以包含其他标签,但我想要整个内容,如字符串
所以我做的是这个
_divTag = data.find( "div" , id = "storytext" )
innerdiv = _divTag.find( "div" ) # find the first div tag
innerdiv.contents[0].replaceWith("") # replace with null
因此 _divTag 将只有主要内容,但这不起作用。谁能告诉我我犯了什么错误以及我应该如何提取主要内容
【问题讨论】:
标签: python beautifulsoup