我正在开发一些屏幕抓取软件,但遇到了 Beautiful Soup 的问题。我正在使用 python 2.4.3 和 Beautiful Soup 3.0.7a。
我需要删除一个<hr>
标签,但它可以有许多不同的属性,所以一个简单的 replace() 调用不会删除它。
给定以下html:
<h1>foo</h1>
<h2><hr/>bar</h2>
以及以下代码:
soup = BeautifulSoup(string)
bad_tags = soup.findAll('hr');
[tag.extract() for tag in bad_tags]
for i in soup.findAll(['h1', 'h2']):
print i
print i.string
输出是:
<h1>foo</h1>
foo
<h2>bar</h2>
None
我是否误解了提取功能,或者这是 Beautiful Soup 的错误?