Submit a WEB form using Python's urllib library

  • 2020-04-02 09:24:34
  • OfStack


class EntryDemo( Frame ): 
"""Demonstrate Entrys and Event binding""" 

chosenrange = 2 
url_login="http://.../ipgw/ipgw.ipgw/" 
uid = ''  # username  
password = '' #  password  
operation = '' #  operation  
range = '2'  #   The scope of  
the_page = ''  #  WEB The server returns to the page  
 #   The form of INPUT  The value must remember to complete  
def login(self): 
values = { 
'uid' : self.uid, 
'password' : self.password, 
'operation' : self.operation, 
'range' : self.range, # 1: The international  2: domestic  
'timeout':'0' 
} 
postdata = urllib.urlencode(values)  #   Form value coding  
req = urllib2.Request(self.url_login, postdata)  #   Server request  
response = urllib2.urlopen(req) 
self.the_page = response.read()

#print self.the_page

Related articles: