June 2000
Intermediate to advanced
556 pages
8h 45m
English
The HTML builder for Python's DOM implementation does a lot of work to infer the locations of missing tags. We can take advantage of this work to have a tool for parsing HTML into PYX format.
CD-ROM reference=11018.txt
C>type html2pyx.py """ Convert HTML to PYX via the DOM """ from xml.dom import core from xml.dom.html_builder import HtmlBuilder import string def Encode (s): # Encode newlines for PYX output. return string.replace (s,"\n","\\n") def OutputPYX(node): if node.nodeType == core.TEXT_NODE: print "-%s" % Encode(node.nodeValue) elif node.nodeType == core.ELEMENT_NODE: print "(%s" % node.nodeName children = node.childNodes for cnode in children: # Recurse for each child node. OutputPYX(cnode) ...Read now
Unlock full access