【发布时间】:2015-06-23 21:30:20
【问题描述】:
我正在尝试使用 BeautifulSoup 来解析一些脏 HTML。一种这样的 HTML 是 http://f10.5post.com/forums/showthread.php?t=1142017
发生的情况是,首先,树错过了页面的一大块。其次,tostring(tree) 会将页面一半上的<div> 等标签转换为&lt;/div&gt; 等HTML 实体。比如
原文:
<div class="smallfont" align="centre">All times are GMT -4. The time now is <span class="time">02:12 PM</span>.</div>`
toString(tree) 给了
<div class="smallfont" align="center">All times are GMT -4. The time now is <span class="time">02:12 PM</span>.</div>
这是我的代码:
from BeautifulSoup import BeautifulSoup
import urllib2
page = urllib2.urlopen("http://f10.5post.com/forums/showthread.php?t=1142017")
soup = BeautifulSoup(page)
print soup
谢谢
【问题讨论】:
标签: python html parsing beautifulsoup html-parsing