【发布时间】:2014-02-08 02:27:42
【问题描述】:
这是我今天早上提出的问题的后续 - Using Beatiful Soup to get data from non-class section
我正在尝试获取一组信息并针对一组关键字进行搜索。如果在信息集中找到关键字,我想保释。但是,即使关键字在信息集中,我的代码也没有找到关键字
negative_keywords = ['basement', 'unfinished', 'hardwood'] #defined at beginning of script
bodyContents = soup.find(attrs={'id' : 'postingbody'})
for validate in negative_keywords:
if (string.find(str(bodyContents.string).lower(),validate) != -1):
keyword_found = TRUE
continue
这是样本数据
<section id="postingbody">
3BR/2BA newly renovated ranch
<p>
<b></b>
</p>
<hr></hr>
<h2>
Some address
</h2>
<h2>
$950.00 / Month
</h2>
<h3 style="color:maroon;">
- Description:
</h3>
<blockquote>
3BR/2BA newly renovated ranch. Near all that Towne…
</blockquote>
<h3 style="color:maroon;">
- Details:
</h3>
<ul>
<li></li>
<li></li>
<li>
<b></b>
No
</li>
<li></li>
<li></li>
<li></li>
<li></li>
【问题讨论】:
标签: python parsing python-2.7 html-parsing beautifulsoup