python get,post 提交表单

xiaoxiao2022-06-12  34

# -*- coding: cp936 -*-import urllib2,urllib,sys"""使用GET在百度搜索引擎上查询在百度的搜索条中随便输入一些内容,会有w和cl两项构成GET串此例演示如何生成GET串,并进行请求."""url = "http://www.baidu.com/s"search = [('w','python'),('cl','3')]getString = url + "?" + urllib.urlencode(search)req = urllib2.Request(getString)fd = urllib2.urlopen(req)while 1:    data = fd.read(1024)    if not len(data):        break    sys.stdout.write(data) *******************************************************************************************************# -*- coding: cp936 -*-import urllib2,urllib,sys"""使用POST提交Form数据1.编码还是使用urlencode2.不必要使用字符串连接3.使用urlopen的data参数例子无法运行,原因是www.google.com只支持GET方式,没有提供POST方式"""url = "http://www.google.com/search"search = urllib.urlencode([('q','python')])req = urllib2.Request(url)fd = urllib2.urlopen(req,search)while 1:    data = fd.read(1024)    if not len(data):        break    sys.stdout.write(data)

相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-4933066.html

最新回复(0)