pythonWeb编程提交表单方法
2015-09-29 10:14
676 查看
Get方法:
Post方法:
''' Created on 2015-9-29 @author: Administrator ''' #/usr/bin/env python #Submit GET Data - Chapter 6 - submit_get.py import sys, urllib2, urllib def addGETdata(url, data): """ Adds data to url. Data should be a list or tuple consisting of 2-item lists or tuples of the form: (key, value). Items that have no key should have key set to None A given key may occur more than once. """ return url + '?' + urllib.urlencode(data) zipcode = sys.argv[1] url = addGETdata('http://www.wunderground.com/cgi-bin/findweather/getForecast', [('query', zipcode)]) print "Using URL", url req = urllib2.Request(url) fd = urllib2.urlopen(req) while 1: data = fd.read(1024) if not len(data): break sys.stdout.write(data)
Post方法:
''' Created on 2015-9-29 @author: Administrator ''' #/usr/bin/env python #Submit POST Data - Chapter 6 - submit_post.py import sys, urllib2, urllib zipcode = sys.argv[1] url = 'http://www.wunderground.com/cgi-bin/findweather/getForecast' data = urllib.urlencode([('query', zipcode)]) req = urllib2.Request(url) fd = urllib2.urlopen(req, data) while 1: data = fd.read(1024) if not len(data): break sys.stdout.write(data)
相关文章推荐
- Python 3 : Convert string to bytes
- Python – How to delay few seconds
- python学习(三):matplotlib学习
- 2015/9/28 Python基础(19):类的定制和私有性
- python使用wxPython创建一个简单的文本编辑器。
- Python – How to loop a dictionary
- python encode和decode函数说明
- Python 网页爬虫
- 3.3.7 使用difflib.get_close_matches函数
- 关于Python中输出中文的一点疑问
- 用python做了一个 qq炫舞 机器人
- enumerate sorted
- Python学习----进程和线程
- Python磁盘监控、日志分析监控脚本
- numpy教程:矩阵matrix及其运算
- Python中bisect模块用法,及实现方式
- numpy教程 - 矩阵及其运算
- python3.4 + django1.8的环境搭建
- python模拟登录网易邮箱
- Python3+Opencv3的安装