[經驗總結]用Python的urllib庫提交WEB表單

來源:互聯網
上載者:User

上次實現的校園網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

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.