上次實現的校園網IP網關登入器其中一個關鍵區段就是提交登入網頁的表單,下面是我的Python實現代碼:
import urllib2,urllib<br /> 1. class EntryDemo( Frame ):<br /> 2. """Demonstrate Entrys and Event binding"""<br /> 3.<br /> 4. chosenrange = 2<br /> 5. url_login="http://.../ipgw/ipgw.ipgw/"<br /> 6. uid = '' #使用者名稱<br /> 7. password = '' # 密碼<br /> 8. operation = '' # 操作<br /> 9. range = '2' # 範圍<br /> 10. the_page = '' # WEB伺服器返回頁面 </p><p> 11. # 表單的INPUT 值一定要記得填齊全<br /> 12. def login(self):<br /> 13. values = {<br /> 14. 'uid' : self.uid,<br /> 15. 'password' : self.password,<br /> 16. 'operation' : self.operation,<br /> 17. 'range' : self.range, # 1:國際 2:國內<br /> 18. 'timeout':'0'<br /> 19. }<br /> 20. postdata = urllib.urlencode(values) # 表單值編碼<br /> 21. req = urllib2.Request(self.url_login, postdata) # 伺服器請求<br /> 22. response = urllib2.urlopen(req)<br /> 23. self.the_page = response.read() import urllib2,urllib<br /> 1. class EntryDemo( Frame ):<br /> 2. """Demonstrate Entrys and Event binding"""<br /> 3.<br /> 4. chosenrange = 2<br /> 5. url_login="http://.../ipgw/ipgw.ipgw/"<br /> 6. uid = '' #使用者名稱<br /> 7. password = '' # 密碼<br /> 8. operation = '' # 操作<br /> 9. range = '2' # 範圍<br /> 10. the_page = '' # WEB伺服器返回頁面<br /> 11. # 表單的INPUT 值一定要記得填齊全<br /> 12. def login(self):<br /> 13. values = {<br /> 14. 'uid' : self.uid,<br /> 15. 'password' : self.password,<br /> 16. 'operation' : self.operation,<br /> 17. 'range' : self.range, # 1:國際 2:國內<br /> 18. 'timeout':'0'<br /> 19. }<br /> 20. postdata = urllib.urlencode(values) # 表單值編碼<br /> 21. req = urllib2.Request(self.url_login, postdata) # 伺服器請求<br /> 22. response = urllib2.urlimport urllib2,urllib<br /> 1. class EntryDemo( Frame ):<br /> 2. """Demonstrate Entrys and Event binding"""<br /> 3.<br /> 4. chosenrange = 2<br /> 5. url_login="http://.../ipgw/ipgw.ipgw/"<br /> 6. uid = '' #使用者名稱<br /> 7. password = '' # 密碼<br /> 8. operation = '' # 操作<br /> 9. range = '2' # 範圍<br /> 10. the_page = '' # WEB伺服器返回頁面<br /> 11. # 表單的INPUT 值一定要記得填齊全<br /> 12. def login(self):<br /> 13. values = {<br /> 14. 'uid' : self.uid,<br /> 15. 'password' : self.password,<br /> 16. 'operation' : self.operation,<br /> 17. 'range' : self.range, # 1:國際 2:國內<br /> 18. 'timeout':'0'<br /> 19. }<br /> 20. postdata = urllib.urlencode(values) # 表單值編碼<br /> 21. req = urllib2.Request(self.url_login, postdata) # 伺服器請求<br /> 22. response = urllib2.url