Guest User

Ibood Box

a guest
Mar 6th, 2013
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4.  
  5. from HTMLParser import HTMLParser
  6. from htmlentitydefs import name2codepoint
  7.  
  8. correctForm = False;
  9.  
  10. class MyHTMLParser(HTMLParser):
  11.  
  12.     def handle_endtag(self, tag):
  13.     global correctForm
  14.     if correctForm == True:         # Form closing tag
  15.         if tag == "form":
  16.             sys.exit(0);
  17.         elif tag == "select":
  18.             print "&"
  19.  
  20.     def handle_starttag(self, tag, attrs):
  21.     global correctForm
  22.     global requireChecked
  23.     global isCheckBox
  24.  
  25.     if sys.argv[1] == "":           # Process any form data?
  26.         correctForm = True;
  27.  
  28.     if correctForm == False:        # Verify if this is the form we want data from
  29.         if tag == "form":
  30.             for attr in attrs:
  31.                 if attr[0] == "id":
  32.                     if attr[1] == sys.argv[1]:
  33.                         correctForm = True;
  34.     else:
  35.         if tag == "select":
  36.             for attr in attrs:
  37.                 if attr[0] == "name":
  38.                         print attr[1]
  39.                         print "="
  40.  
  41.         elif tag == "option":
  42.             for attr in attrs:
  43.                 if attr[0] == "selected":
  44.                     for attr in attrs:
  45.                         if attr[0] == "value":
  46.                                 print attr[1]
  47.  
  48.         elif tag == "input":
  49.             requireChecked = False;
  50.  
  51.             for attr in attrs:
  52.                 if attr[0] == "type" and attr[1] == "radio":
  53.                     requireChecked = True;
  54.                 elif attr[0] == "type" and attr[1] == "checkbox":
  55.                     requireChecked = True;
  56.                 elif attr[0] == "disabled" and attr[1] == "true":
  57.                     return;
  58.  
  59.             if requireChecked == True:
  60.                 for attr in attrs:
  61.                     if attr[0] == "checked":
  62.                         requireChecked = False;
  63.    
  64.             if requireChecked == False:
  65.                 for attr in attrs:
  66.                     if attr[0] == "name":
  67.                             print attr[1]
  68.                             print "="
  69.                         for attr in attrs:
  70.                             if attr[0] == "value":
  71.                                     print attr[1]
  72.                         print "&"
  73.                    
  74.  
  75. parser = MyHTMLParser()
  76. parser.feed( sys.stdin.read() )
Advertisement
Add Comment
Please, Sign In to add comment