473,587 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTML -> text/plain "clever" formatting

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

Jul 18 '05 #1
4 3043
Gilles Lenfant wrote:
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.
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/AbstractFormatt er.
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.

But I need a 100% pythonic stuff to have my app (Zope product) running on
non Unix boxes.
That would be 100% pythonic even w/o external stuff.

Any hint ?

Thanks in advance.

--Gilles


HTH Karl

Jul 18 '05 #2
"Karl Scalet" <ne**@yebu.de > a écrit dans le message de news:
bl************@ ID-141451.news.uni-berlin.de...
Gilles Lenfant wrote:
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.


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/AbstractFormatt er.
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.

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


That would be 100% pythonic even w/o external stuff.

Any hint ?

Thanks in advance.

--Gilles


HTH Karl


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

Jul 18 '05 #3
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.Str ingIO()
z=formatter.Abs tractFormatter( formatter.DumbW riter(f))
p=htmllib.HTMLP arser(z)
p.feed(urllib.u nquote_plus(a))
p.close()
sret=f.getvalue ()
f.close()
return(sret)
a="""<HTML><BOD Y><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
Jul 18 '05 #4
Gilles Lenfant wrote:

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


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

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

163
14591
by: Shiperton Henethe | last post by:
Hi Know any good utilities to help me strip out the tags that Microsoft Excel 2002 leaved behind when you try and export an HTML format file? This is driving me NUTS. And really makes me hate microsoft with a passion. I literally just want "compact HTML" - ie just the data,
2
14840
by: Dustin D. | last post by:
If a user prints an html file, is there a way to display page numbers on the document using cascading style sheets or something of that sort? I have a document that is generated dynamically by form data using Perl, and would like some sort of page numbering system on each page. It seems like some browsers have the option to print page #'s,...
19
9118
by: Fran?ois Laroche | last post by:
hey guys, I know that you will tell me that's easier to do in php or even in asp, but I just dont have the time to learn it 1- I need a javascript that will show the date of tomorrow 2- I need a javascript that will show the date in 2 days actually I have a script that show me the current date.... there it is: <script>
15
3373
by: Enzo | last post by:
Hi Ng, It's possible to protect the source code of a js file? With PHP? Thanks in advance! Enzo
2
3773
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently,...
2
2889
by: tombraun | last post by:
Hello! This is my first posting here! :-) I hope you can help me... To sum it up: I have a question about the possibility to influence the execution of JavaScript in another frame. I cannot modify that other frame's code, but it does come from the same server. Therefore, there should not be an issue with any cross-side scripting...
3
1470
by: JezB | last post by:
What's the generally accepted approach for using Styles and Stylesheets in a web application based on .aspx files, Web Controls, User Controls, and code-behind modules (c# in my case)? Most style and stylesheet guides on the internet seem to be based on web sites (rather than applications) based on relatively static textual information. I...
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.