XML-DOM slow?

Mordy Ovits movits at lockstar.com
Tue Jul 13 12:22:15 EDT 1999


I've been playing around with the XML libraries, to great effect.  I
can't believe how useful it is.   However, it seems to be very slow. 
The (short) program at the bottom of this email takes about 10 seconds
to run!
What am I doing wrong?  Am I defaulting to a slow parser?
Thanks!
Mordy
-----------------------------------------
#!/usr/bin/python
                   
from xml.dom.html_builder import HtmlBuilder
import urllib
from sys import argv

s = urllib.urlopen(argv[1])

htmlstr = s.read()

b = HtmlBuilder()

b.ignore_mismatched_end_tags = 1
b.feed(htmlstr)  
doc = b.document

anchors = doc.getElementsByTagName('A')
for a in anchors:
    if a._node.attributes.has_key("HREF"):
        href = a._node.attributes["HREF"]
        print "Title: ", a._node.children[0].value
        print "Link: ", href.children[0].value
        print
    else:
        print "error in <A> (?)"
        print a._node.attributes
-------------------
-- 
o Mordy Ovits
o Cryptographic Engineer
o LockStar Inc.
---------------------------------------------------------------------------
#!/usr/local/bin/python 
from sys import*;from string import*;a=argv;[s,p,q]=filter(lambda
x:x[:1]!=
'-',a);d='-d'in
a;e,n=atol(p,16),atol(q,16);l=(len(q)+1)/2;o,inb=l-d,l-1+d
while s:s=stdin.read(inb);s and map(stdout.write,map(lambda
i,b=pow(reduce(
lambda x,y:(x<<8L)+y,map(ord,s)),e,n):chr(b>>8*i&255),range(o-1,-1,-1)))




More information about the Python-list mailing list