BeautifulSoup实体引用问题

新手上路,请多包涵
template = codecs.open('template.html', 'r' , 'utf-8')
template = template.read()
template = bs(template)

resp = requests.get('http://blog.jobbole.com/61171/')
html = resp.text.encode('utf-8')

html = bs(html)
t = html.title.string

template.title.string = t
template.div.string = str(html.select('div.entry')[0])

out = codecs.open(''.join(['result/', t, '.html']), 'w' , 'utf-8')
# out.write(str(template))

# print(template)
print(str(html.select('div.entry')[0]))

如果直接输出 str(html.select('div.entry')[0]) 时尖括号不会转义,
但输出 template 就会转义。

现在我想让template就保持原样(既不escape也不unescape)应该怎样做呢?谢谢大家了。

阅读 1.8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题