我想把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?还是我做错了,应该采取不同的方法?在
将传递给BeautifulGroup的值转换为字符串。 对于您的情况,请对最后一行执行以下编辑:
只需将^{} 环绕
cleaned_html
把它传给Beautiulsoup。在相关问题 更多 >
编程相关推荐