browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need Python help?

Get answers from our community of Python experts on BYTES! It's free.

HTML -> text/plain "clever" formatting

Gilles Lenfant
Guest
 
Posts: n/a
#1: Jul 18 '05
Hi,

I make an app where I need to convert HTML to text in a "clever" way (means
it tries to mimic when possible a browser rendering).
Actually I spawn with popen2 a "lynx" that makes a perfect job.

But I need a 100% pythonic stuff to have my app (Zope product) running on
non Unix boxes.

Any hint ?

Thanks in advance.

--Gilles




Karl Scalet
Guest
 
Posts: n/a
#2: Jul 18 '05

re: HTML -> text/plain "clever" formatting


Gilles Lenfant wrote:[color=blue]
> Hi,
>
> I make an app where I need to convert HTML to text in a "clever" way (means
> it tries to mimic when possible a browser rendering).
> Actually I spawn with popen2 a "lynx" that makes a perfect job.[/color]

i've seen an example in python cookbook, but do not have the copy with
me right now. If you have that book, look at the example to send HTML
mails. keywords are htmllib and formatter/AbstractFormatter.
IIRC they mention it's not that perfect as doing the same with lynx.
Don't know if the onlineversion at activestate does have this example.
[color=blue]
>
> But I need a 100% pythonic stuff to have my app (Zope product) running on
> non Unix boxes.[/color]

That would be 100% pythonic even w/o external stuff.
[color=blue]
>
> Any hint ?
>
> Thanks in advance.
>
> --Gilles
>[/color]

HTH Karl

Gilles Lenfant
Guest
 
Posts: n/a
#3: Jul 18 '05

re: HTML -> text/plain "clever" formatting


"Karl Scalet" <news@yebu.de> a écrit dans le message de news:
blrgg6$epn59$1@ID-141451.news.uni-berlin.de...[color=blue]
> Gilles Lenfant wrote:[color=green]
> > Hi,
> >
> > I make an app where I need to convert HTML to text in a "clever" way[/color][/color]
(means[color=blue][color=green]
> > it tries to mimic when possible a browser rendering).
> > Actually I spawn with popen2 a "lynx" that makes a perfect job.[/color]
>
> i've seen an example in python cookbook, but do not have the copy with
> me right now. If you have that book, look at the example to send HTML
> mails. keywords are htmllib and formatter/AbstractFormatter.
> IIRC they mention it's not that perfect as doing the same with lynx.
> Don't know if the onlineversion at activestate does have this example.
>[color=green]
> >
> > But I need a 100% pythonic stuff to have my app (Zope product) running[/color][/color]
on[color=blue][color=green]
> > non Unix boxes.[/color]
>
> That would be 100% pythonic even w/o external stuff.
>[color=green]
> >
> > Any hint ?
> >
> > Thanks in advance.
> >
> > --Gilles
> >[/color]
>
> HTH Karl
>[/color]

Thanks Karl, I found what you're talking about

http://aspn.activestate.com/ASPN/Coo...n/Recipe/52297

Need to rework that TtyFormatter in depth to mimic lynx :o)

Cheers

--Gilles

Michel Claveau/Hamster
Guest
 
Posts: n/a
#4: Jul 18 '05

re: HTML -> text/plain "clever" formatting


Bonjour !

Tente l'exemple de code "maison" ci-dessous.

@-salutations
--
Michel Claveau
mél : http://cerbermail.com/?6J1TthIa8B





# -*- coding: cp1252 -*-

import cStringIO
import formatter
import urllib
import htmllib

def htdecode(a):
f=cStringIO.StringIO()
z=formatter.AbstractFormatter(formatter.DumbWriter (f))
p=htmllib.HTMLParser(z)
p.feed(urllib.unquote_plus(a))
p.close()
sret=f.getvalue()
f.close()
return(sret)


a="""<HTML><BODY><B> Bonjour%20!%20<BR>
Ligne 2</B></BODY></HTML>"""

print '\n--- en HTML','-'*30
print a

b=htdecode(a)

print '\n\n--- sans HTML','-'*28
print b


Karl Scalet
Guest
 
Posts: n/a
#5: Jul 18 '05

re: HTML -> text/plain "clever" formatting


Gilles Lenfant wrote:
[color=blue]
>
> Thanks Karl, I found what you're talking about
>
> http://aspn.activestate.com/ASPN/Coo...n/Recipe/52297
>
> Need to rework that TtyFormatter in depth to mimic lynx :o)
>
> Cheers
>[/color]

Hi Gilles

actually I was talking about a different even similar example.
But could not find it either in the online version. So maybe
this is available only in the printed version, sorry.
But if your recipe is good enough , why bother :-)

Karl

Closed Thread