Python模拟http get
2018-07-20 来源:open-open
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 = 'S2S 7U8'
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)
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:Go语言使用http下载文件
下一篇: Go语言实现简单的文件服务器
最新资讯
热门推荐