#!/usr/bin/python python """Traverse filespec of *.html looking for select tag and write out report of options.""" import os import sys from xml.sax.saxutils import escape def process(filename, fp): print "* Processing:", filename, "\n" # parse the file select_of_htmlFile = open(filename) fp.write("

Filename: " + filename + "

\n") prefix = "

" inSelect = 0 line = select_of_htmlFile.readline( ) while line: line = " " + line.strip( ) if line.find(" 0: if inSelect: fp.write(prefix + "

\n") inSelect = 1 if line.find("id=") > 0: v = line.index("id=") dm = line[(v+3):(v+4)] v2 = line[(v+4):].index(dm) + v + 4 fp.write("

Dropdown: " + line[(v+4):v2] + "

\n") if line.find("") > 0: if inSelect: fp.write(prefix + "

\n") inSelect = 0 elif line.find("document.write") > 0: inSelect = inSelect elif line.find(" 0 and line.find("<") > 0 and inSelect: v2 = line.index("") + v2 v2 = line[v:].index("<") + v fp.write(prefix + line[(v+1):v2] + "
\n") prefix = "" line = select_of_htmlFile.readline( ) select_of_htmlFile.close( ) if inSelect: fp.write(prefix + "

\n") prefix = "" inSelect = 0 def finder(fp, dirname, names): """Add files in the directory dirname to a list.""" for name in names: if name.endswith(".html"): path = os.path.join(dirname, name) if os.path.isfile(path): process(path, fp) def main( ): print "[extract_select_option_values.py started]" xmlFd = open("extract_select_option_values.htm", "w") xmlFd.write("\n") xmlFd.write("\n") os.path.walk(sys.argv[1], finder, xmlFd) xmlFd.write("\n") xmlFd.write("\n") xmlFd.close( ) print "[extract_select_option_values.py finished]" if __name__ == "__main__": main( )