用Python的urllib库提交WEB表单

yipeiwu_com5年前Python基础
复制代码 代码如下:

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

chosenrange = 2
url_login="http://.../ipgw/ipgw.ipgw/"
uid = '' #用户名
password = '' # 密码
operation = '' # 操作
range = '2' # 范围
the_page = '' # WEB服务器返回页面
# 表单的INPUT 值一定要记得填齐全
def login(self):
values = {
'uid' : self.uid,
'password' : self.password,
'operation' : self.operation,
'range' : self.range, # 1:国际 2:国内
'timeout':'0'
}
postdata = urllib.urlencode(values) # 表单值编码
req = urllib2.Request(self.url_login, postdata) # 服务器请求
response = urllib2.urlopen(req)
self.the_page = response.read()

#print self.the_page

相关文章

Python计算两个日期相差天数的方法示例

本文实例讲述了Python计算两个日期相差天数的方法。分享给大家供大家参考,具体如下: #!/usr/bin/python import time import sys def da...

Python使用try except处理程序异常的三种常用方法分析

本文实例讲述了Python使用try except处理程序异常的三种常用方法。分享给大家供大家参考,具体如下: 如果你在写python程序时遇到异常后想进行如下处理的话,一般用try来处...

Python学习小技巧之利用字典的默认行为

本文介绍的是关于Python利用字典的默认行为的相关内容,分享出来供大家参考学习,下面来看看详细的介绍: 典型代码1: from collections import defaul...

python字符串编码识别模块chardet简单应用

python的字符串编码识别模块(第三方库): 官方地址: http://pypi.python.org/pypi/chardet import chardet import...

基于Python中的yield表达式介绍

基于Python中的yield表达式介绍

python生成器 python中生成器是迭代器的一种,使用yield返回函数值。每次调用yield会暂停,而可以使用next()函数和send()函数可以恢复生成器。 这里可以参考Py...