1、获取web页面
#coding:utf-8 import sys,urllib2 req=urllib2.Request(sys.argv[1]) fd=urllib2.urlopen(req) while 1: data=fd.read(1024) if not len(data): break print data
2、GET提交数据
#coding:utf-8 import sys.urllib,urllib2 def addGETdata(url,data): return url+‘?‘+urllib.urlencode(data) code=sys.argv[1] url=addGETdata(‘http://www.baidu.com/xx.php‘,[(‘id‘,code)]) print "URL:",url req=urllib2.Request(url) fd=urllib2.urlopen(req) while 1: data=fd.read(1024) if not len(data): break print data
3、POST提交数据
#coding:utf-8 import sys.urllib,urllib2 code=sys.argv[1] url="http://www.baidu.com/xx.php" data=urllib.urlencode([(‘id‘,code)]) req=urllib2.Request(url) fd=urllib2.urlopen(req) while 1: data=fd.read(1024) if not len(data): break print data
4、未完待续!
时间: 2024-10-07 22:19:33