Article View: es.comp.os.linux.programacion
Article #193html entities y unicode con python
From: Benjamín Albiñana Pérez
Date: Sat, 14 Apr 2012 18:51
Date: Sat, 14 Apr 2012 18:51
32 lines
2329 bytes
2329 bytes
A ver si consigo explicarme: Primer intento: >>> fromm BeautifulSoup import BeautifulSoup as BS >>> html_data = """ >>> ... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >>> "http://www.w3.org/TR/html4/loose.dtd"> >>> ... <html lang="es"> >>> ... <head> >>> ... <meta http-equiv="Content-Type" content="text/html; >>> charset=iso-8859-1"> >>> ... </head> >>> ... <body> >>> ... Corrección de errores a la Resolución >>> ... </body> >>> ... </html> >>> ... """ >>> soup = BS(html_data, convertEntities=BS.HTML_ENTITIES) >>> print soup.body.text Corrección de errores a la Resolución Segundo intento: >>> import HTMLParser >>> s = "Corrección de errores a la Resolución" >>> parser = HTMLParser.HTMLParser() >>> parser.unescape(s) >>> u'Correcci\xf3n de errores a la Resoluci\xf3n' Y aquí ya no sé como seguir, porque lo que yo quiero es "Correción de errores a la Resolución" ¿Alguna idea?
Technical Details
Message-ID:
<slrnjojhr5.l8h.benalb@furia.eg>Path:
arc1-ca.pugleaf.net!h15ni123549bkw.0!nntp.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: f86c8,2ea3196dd6959a2,start
X-Google-NewGroupId: yes
X-Google-Attributes: gid646d03421f,domainid0,public,usenet
X-Google-Language: SPANISH,UTF8
Received: by 10.204.13.69 with SMTP id b5mr579900bka.4.1334429525557;
Sat, 14 Apr 2012 11:52:05 -0700 (PDT)
Path: arc1-ca.pugleaf.net!h15ni123549bkw.0!nntp.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From: Benjamín Albiñana Pérez <benalb@gmail.com>
Newsgroups: es.comp.os.linux.programacion
Subject: html entities y unicode con python
Date: Sat, 14 Apr 2012 20:51:50 +0200
Organization: Expect No Quarter, Inc.
Lines: 33
Message-ID: <slrnjojhr5.l8h.benalb@furia.eg>
Mime-Version: 1.0
Injection-Info: mx04.eternal-september.org; posting-host="R9WQQH/5rN3WtWPRUFjMpw";
logging-data="9048"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18P23GjEIVgtlYZhEognLNT"
User-Agent: slrn/pre1.0.0-18 (Linux)
Cancel-Lock: sha1:vgdA287B9SXNsnV9S3N/wfDnEkU=
X-Received-Bytes: 1844
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit