[Python-es] Convertir utf8 a html entities

Raúl Cumplido raulcumplido en gmail.com
Mar Jun 5 14:00:59 CEST 2012


Según la documentación oficial:

http://docs.python.org/library/htmllib.html#module-htmlentitydefs

2012/6/5 Raimon Esteve <raimonesteve en gmail.com>

> Hola,
>
> he leido de todo y nada me ha gustado. Como convertís un string utf8 a
> un string con carácteres html? o sea, que los accentos se transformen
> a codificación html?
>
> En este pequeño código, convertimos á é í ó ú ñ -> a htm entities.
> Pero falta mayúsculas, ç (catalán), ....
>
> import re
>
> value u'Camión'
>
> value = re.sub(r'\xe1', "&aacute;", value)
> value = re.sub(r'\xe9', "&eacute;", value)
> value = re.sub(r'\xed', "&iacute;", value)
> value = re.sub(r'\xf3', "&oacute;", value)
> value = re.sub(r'\xfa', "&uacute;", value)
> value = re.sub(r'\xf1', "&ntilde;", value)
>
> --
> Si us plau, NO adjunti arxius a les seves respostes. Li preguem que
> integri el text al cos del missatge. Pot respondre usant NetEtiquete
> que li ajudarà a seguir la conversa.
> http://es.wikipedia.org/wiki/Netiquette
>
> Por favor, NO adjunte archivos a sus respuestas. Le rogamos que
> integre el texto en el cuerpo del mensaje. Puede responder usando
> NetEtiquete que le ayudará a seguir la
> conversación.http://es.wikipedia.org/wiki/Netiquette
>
> Please, DO NOT send attachment files with your answers, just copy and
> paste only the text you need to send into the body of your mails.
> Repply using NetEtiquete. http://en.wikipedia.org/wiki/Netiquette
> _______________________________________________
> Python-es mailing list
> Python-es en python.org
> http://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/
>



-- 
Raúl Cumplido
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20120605/b8e78a85/attachment.html>


Más información sobre la lista de distribución Python-es