Article View: es.comp.os.linux.programacion
Article #301Re: python, beautifulsoup y utf
From: Mario Teijeiro Otero
Date: Sun, 10 May 2009 12:23
Date: Sun, 10 May 2009 12:23
50 lines
2196 bytes
2196 bytes
pspbar@gmail.com wrote:
Me da que no están bien definidas las variables LC_XX en la tarea del cron.
Intenta definirlas al crear la tarea del crontab.
Un saludo
> 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:
<gu6gvf$2cc$1@cormoran.emeteo.local>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder.news-service.com!news.netcologne.de!newsfeed-fusi2.netcologne.de!newsfeed.straub-nv.de!news.antakira.com!cagarruta.escomposlinux.org!cernicalo.escomposlinux.org!escomposlinux.org!not-for-mailReferences:
<6c878115-9632-4aed-8c11-e77241abb87a@l28g2000vba.googlegroups.com>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,UTF8 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder.news-service.com!news.netcologne.de!newsfeed-fusi2.netcologne.de!newsfeed.straub-nv.de!news.antakira.com!cagarruta.escomposlinux.org!cernicalo.escomposlinux.org!escomposlinux.org!not-for-mail From: Mario Teijeiro Otero <emeteo@escomposlinux.org> Newsgroups: es.comp.os.linux.programacion Subject: Re: python, beautifulsoup y utf Date: Sun, 10 May 2009 14:23:11 +0200 Organization: Ecolnet Lines: 51 Message-ID: <gu6gvf$2cc$1@cormoran.emeteo.local> References: <6c878115-9632-4aed-8c11-e77241abb87a@l28g2000vba.googlegroups.com> NNTP-Posting-Host: 10.8.0.2 Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8Bit X-Trace: cormoran.emeteo.local 1241958192 2444 10.8.0.2 (10 May 2009 12:23:12 GMT) X-Complaints-To: emeteo@escomposlinux.org NNTP-Posting-Date: Sun, 10 May 2009 12:23:12 +0000 (UTC) User-Agent: KNode/0.10.9