[经验总结]用Python的urllib库提交WEB表单

上次实现的校园网IP网关登录器其中一个关键部分就是提交登录网页的表单,下面是我的Python实现代码:

import urllib2,urllib 1. class EntryDemo( Frame ): 2. """Demonstrate Entrys and Event binding""" 3. 4. chosenrange = 2 5. url_login="http://.../ipgw/ipgw.ipgw/" 6. uid = '' #用户名 7. password = '' # 密码 8. operation = '' # 操作 9. range = '2' # 范围 10. the_page = '' # WEB服务器返回页面 11. # 表单的INPUT 值一定要记得填齐全 12. def login(self): 13. values = { 14. 'uid' : self.uid, 15. 'password' : self.password, 16. 'operation' : self.operation, 17. 'range' : self.range, # 1:国际 2:国内 18. 'timeout':'0' 19. } 20. postdata = urllib.urlencode(values) # 表单值编码 21. req = urllib2.Request(self.url_login, postdata) # 服务器请求 22. response = urllib2.urlopen(req) 23. self.the_page = response.read() import urllib2,urllib 1. class EntryDemo( Frame ): 2. """Demonstrate Entrys and Event binding""" 3. 4. chosenrange = 2 5. url_login="http://.../ipgw/ipgw.ipgw/" 6. uid = '' #用户名 7. password = '' # 密码 8. operation = '' # 操作 9. range = '2' # 范围 10. the_page = '' # WEB服务器返回页面 11. # 表单的INPUT 值一定要记得填齐全 12. def login(self): 13. values = { 14. 'uid' : self.uid, 15. 'password' : self.password, 16. 'operation' : self.operation, 17. 'range' : self.range, # 1:国际 2:国内 18. 'timeout':'0' 19. } 20. postdata = urllib.urlencode(values) # 表单值编码 21. req = urllib2.Request(self.url_login, postdata) # 服务器请求 22. response = urllib2.urlimport urllib2,urllib 1. class EntryDemo( Frame ): 2. """Demonstrate Entrys and Event binding""" 3. 4. chosenrange = 2 5. url_login="http://.../ipgw/ipgw.ipgw/" 6. uid = '' #用户名 7. password = '' # 密码 8. operation = '' # 操作 9. range = '2' # 范围 10. the_page = '' # WEB服务器返回页面 11. # 表单的INPUT 值一定要记得填齐全 12. def login(self): 13. values = { 14. 'uid' : self.uid, 15. 'password' : self.password, 16. 'operation' : self.operation, 17. 'range' : self.range, # 1:国际 2:国内 18. 'timeout':'0' 19. } 20. postdata = urllib.urlencode(values) # 表单值编码 21. req = urllib2.Request(self.url_login, postdata) # 服务器请求 22. response = urllib2.url

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值