Article View: es.comp.os.linux.programacion
Article #300python, beautifulsoup y utf
From: pspbar
Date: Sun, 10 May 2009 12:09
Date: Sun, 10 May 2009 12:09
42 lines
2067 bytes
2067 bytes
Hola
tengo un script en python y beautifulsoup con el que accedo a una
página web e imprimo en pantalla
unos cuantos datos, todo muy sencillo.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
from BeautifulSoup import BeautifulSoup
page = urllib2.urlopen("http://www.onlae.es/primitiva/comprobar.aspx")
soup = BeautifulSoup(page)
page.close()
(...)
# Fecha del sorteo
sorteo = soup.find("h2", {"class" : "sorteo"})
print sorteo.string
(...)
Desde la consola, al ejecutar el script todo funciona sin problemas:
~$ tmp/loto.py
Sorteo
19/S, sábado, 09 de mayo de 2009
(...)
Pero si el script se ejecuta desde crontab, me da un error de
codificación:
Traceback (most recent call last):
File "/home/user/tmp/loto.py", line 25, in <module>
print sorteo.string
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in
position 31: ordinal not in range(128)
¿Alguna idea de como solucionar esto?
Technical Details
Message-ID:
<6c878115-9632-4aed-8c11-e77241abb87a@l28g2000vba.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!l28g2000vba.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!l28g2000vba.googlegroups.com!not-for-mail From: "pspbar@gmail.com" <pspbar@gmail.com> Newsgroups: es.comp.os.linux.programacion Subject: python, beautifulsoup y utf Date: Sun, 10 May 2009 05:09:42 -0700 (PDT) Organization: http://groups.google.com Lines: 42 Message-ID: <6c878115-9632-4aed-8c11-e77241abb87a@l28g2000vba.googlegroups.com> NNTP-Posting-Host: 80.32.232.60 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1241957383 31315 127.0.0.1 (10 May 2009 12:09:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 10 May 2009 12:09:43 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l28g2000vba.googlegroups.com; posting-host=80.32.232.60; posting-account=EG5mRgoAAABhgAJctSG-rGTZOfVzdSNw User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en; rv:1.9.0.10) Gecko/20080528 Epiphany/2.22 Firefox/3.0,gzip(gfe),gzip(gfe)