玩蛇网提供最新Python编程技术信息以及Python资源下载!

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)应该怎样做呢?谢谢大家了。

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd18567.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年06月02日 - 17时15分17秒 发布自玩蛇网

您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容
我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules