我想用BeautifulSoup来解析一些肮脏的HTML。一个这样的HTML是http://f10.5post.com/forums/showthread.php?t=1142017
结果是,首先,树丢失了一大块页面。其次,tostring(tree)
会将页面一半上的<div>
这样的标记转换成</div>
这样的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
谢谢
使用^{} 和极其宽大的^{eem>^{cd2>}parser:
相关问题 更多 >
编程相关推荐