欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python執(zhí)行g(shù)et提交的方法

 更新時間:2015年04月29日 10:02:40   作者:重負在身  
這篇文章主要介紹了python執(zhí)行g(shù)et提交的方法,實例分析了Python通過get傳遞數(shù)據(jù)的技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了python執(zhí)行g(shù)et提交的方法。分享給大家供大家參考。具體如下:

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.yoursiteweb.com/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)

希望本文所述對大家的Python程序設(shè)計有所幫助。

相關(guān)文章

最新評論