靓汤乌蒂

2024-10-01 13:40:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把utidy的结果传给美丽的汤,阿拉:

page = urllib2.urlopen(url)
options = dict(output_xhtml=1,add_xml_decl=0,indent=1,tidy_mark=0)
cleaned_html = tidy.parseString(page.read(), **options)
soup = BeautifulSoup(cleaned_html)

运行时,会出现以下错误:

^{pr2}$

我发现utidy返回一个XML文档,而beauthulsoup需要一个字符串。有没有一种方法可以投射干净的html?还是我做错了,应该采取不同的方法?在


Tags: 方法addurloutputhtmlpagexmlurllib2