用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 使用opencv 把视频分割成图片示例

我就废话不多说了,直接上代码吧! #--coding:utf-8-- import cv2 #图像路径名字错误不提示 im=cv2.imread("timg.jpg",cv2...

对python中dict和json的区别详解

1、json 和 字典 区别 >>>import json >>>json.dumps({1:2}) >>>'{"1":2}...

python使用socket远程连接错误处理方法

本文实例讲述了python使用socket远程连接错误处理方法。分享给大家供大家参考。具体如下: import socket, sys host = sys.argv[1] text...

Python实现统计代码行的方法分析

Python实现统计代码行的方法分析

本文实例讲述了Python实现统计代码行的方法。分享给大家供大家参考,具体如下: 参加光荣之路测试开发班已三月有余,吴总上课也总问“ 咱们的课上了这么多次了大家实践了多少行代码了?”。这...

Django框架中render_to_response()函数的使用方法

通常的情况是,我们一般会载入一个模板文件,然后用 Context渲染它,最后返回这个处理好的HttpResponse对象给用户。 我们已经优化了方案,使用 get_template()...