473,804 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trimming X/HTML files

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dear,

I need to parse XHTML/HTML files in all ways :
~ _ Removing comments and javascripts is a first issue
~ _ Retrieving the list of fields to submit is my following item (todo)

Any idea where I could find this already made ... ?

\T,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFC6CAqqN0 SJr+xLBURAkc5AK CAb5pdsUZjCezr8 bcpd2GTJ9FueACg 7raK
pMU5Y4Z7PaPGfGZ kJ/wCDpw=
=iM7V
-----END PGP SIGNATURE-----
Jul 28 '05 #1
2 1453
Thomas SMETS wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dear,

I need to parse XHTML/HTML files in all ways :
~ _ Removing comments and javascripts is a first issue
~ _ Retrieving the list of fields to submit is my following item (todo)

Any idea where I could find this already made ... ?


You could try XIST (http://www.livinglogic.de/Python/xist).

Removing comments and javascripts works like this:

---
from ll.xist import xsc, parsers
from ll.xist.ns import html

e = parsers.parseUR L("http://www.python.org/", tidy=True)

def removestuff(nod e, converter):
if isinstance(node , xsc.Comment):
node = xsc.Null
elif isinstance(node , html.script) and \
(unicode(node["type"]) == u"text/javascript" or \
unicode(node["language"]) == u"Javascript " \
):
node = xsc.Null
return node

e = e.mapped(remove stuff)

print e.asBytes()
---

Retrieving the list of fields from all forms on a page might look like this:

---
from ll.xist import xsc, parsers, xfind
from ll.xist.ns import html

e = parsers.parseUR L("http://www.python.org/", tidy=True)

for form in e//html.form:
print "Fields for %s" % form["action"]
for field in form//xfind.is_(html. input, html.textarea):
if "id" in field.attrs:
print "\t%s" % field["id"]
else:
print "\t%s" % field["name"]
---

This prints:

Fields for http://www.google.com/search
q
domains
sitesearch
sourceid
submit

Hope that helps!

Bye,
Walter Dörwald
Jul 28 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
The regular expression remove script out of an HTML/XHTML file is simple
enough but raises a major performance issue....

The following regular expression :
r'(<script(\s*\ S+\s*)+</script>)'
takes ages to complete in python on simple HTML file more than 3 minutes
of CPU time on a 150 lines HTML file. In jython it just never completes
but returns a painfull RunTimeExceptio n : maximum number of ??? reached.

Is the only way out dealing with strings and "match" instead of regular
expression ?
More over Jython is not yet 2.3 compliant, hence advanced features of
2.3 regular expression are not yet available !

\T,


Thomas SMETS wrote:
|
| Dear,
|
| I need to parse XHTML/HTML files in all ways :
| ~ _ Removing comments and javascripts is a first issue
| ~ _ Retrieving the list of fields to submit is my following item (todo)
|
| Any idea where I could find this already made ... ?
|
| \T,
|
|

- --
Thomas SMETS
Bruxelles
@ : du************* *@yahoo.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD4DBQFC7OkTqN0 SJr+xLBURAuTYAK DLxLv+hpnSrZ6uo wOmUczVxgxLqwCY hfJ3
fwjPZzg88gh3lNY 8jkG3SA==
=urIC
-----END PGP SIGNATURE-----
Jul 31 '05 #3

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

Similar topics

2
1379
by: Simon | last post by:
Hi there. I seem to be a flurry of questions here recently, thanks for you help all, but ... got another question here. I am storing URL in a database for a 'sort of' directory type website. The <a href> is built from the recordset of URL's which is all working no problem, easy stuff.
6
4835
by: Generic Usenet Account | last post by:
I have worked out the following implementation for trimming the leading and trailing whitespace characters of a string (I am surprised not to see these as member functions). Am I doing it correctly, or is there a better way to do it? Thanks, Gus //////////// Source code begin /////////////////////
12
17119
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested. This is okay in some cases (such as <tbody>), but problematic for other tags (such as <option>). Some tags (td, th, ...) do not produce warnings when they are empty.
13
3676
by: john_g83 | last post by:
have a bit of c code that is ment to take a string (that may or may not have spaces before or after the string) i.e. " stuff ", and trims off the whitespace before and after. Code: char *trim (char *str, char ch) { char *first, *last; int count;
4
1192
by: Chris | last post by:
Hi, I have the follwing url http://localhost/testsite/test/webform1.aspx?cat=dog Is there a function available in the request.url object to return only the webform1.aspx or even /webform1.aspx? Thanks
0
1213
by: Paul | last post by:
On my local site, I have a folder that is security trimmed, so that only members of a Role can see it after they register and log on (I set the memberships). All works fine locally. However, when I deployed to my ISP, the security trimming does not work. Here is the relevant code. I can add users just fine, they show up in the ISP SQL Server database, and I can log on and off.
3
1959
by: Enyi | last post by:
Situation : Need to get a list of files in a directory, but I am currently getting the whole path of the file (Example: "C:\A Folder\Another Folder\file.txt"). What I want is just the filename and extension. So from above example, all I actually want is "file.txt". Language: VB.NET 2005 Current Code: Imports System.Collections.ObjectModel ... Dim files As ReadOnlyCollection(Of String)
7
1840
by: veg_all | last post by:
I am looking for a simple way to keep my log files from growing too large. Basically I would want something that truncates the off first 25 kb of a 100kb log file. I could do something with reading in the file twice, first to determine number of lines. Then a second time to write a copy of the reduced log file. Any simpler workarounds?
1
1305
by: Harald Korneliussen | last post by:
Can anyone tell me of a program that does this? When working on large applications that promiscously include large header files, it would be nice to have an automatic way of figuing out which aren't needed any longer. Any IDEs? Or could someone give me a lint?
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10356
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9176
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
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
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.