如何呈现UNI code标记的内容BeautifulSoup? [英] How to render contents of a tag in unicode in BeautifulSoup?

查看:118
本文介绍了如何呈现UNI code标记的内容BeautifulSoup?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从Word preSS后详细页汤:

This is a soup from a WordPress post detail page:

content = soup.body.find('div', id=re.compile('post'))
title = content.h2.extract()
item['title'] = unicode(title.string)
item['content'] = u''.join(map(unicode, content.contents))

我想省略封闭 DIV 标签分配时项目['内容'] 。有什么办法来呈现在UNI code标记的所有子标签?是这样的:

I want to omit the enclosing div tag when assigning item['content']. Is there any way to render all the child tags of a tag in unicode? Something like:

item['content'] = content.contents.__unicode__()

这会给我一个单向code字符串,而不是名单。

that will give me a single unicode string instead of a list.

推荐答案

你试过:

unicode(content)

它转换的标记到一个单一的统一code字符串的内容

编辑:如果你不想封闭标记,请尝试:

If you don't want the enclosing tag, try:

content.renderContents()

这篇关于如何呈现UNI code标记的内容BeautifulSoup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆