[Python] python执行get提交的操作 →→→→→进入此内容的聊天室

来自 , 2020-06-26, 写在 Python, 查看 139 次.
URL http://www.code666.cn/view/f3f1fa1e
  1. import sys, urllib2, urllib
  2.  
  3. def addGETdata(url, data):
  4.     """Adds data to url.  Data should be a list or tuple consisting of 2-item
  5.    lists or tuples of the form: (key, value).
  6.  
  7.    Items that have no key should have key set to None.
  8.  
  9.    A given key may occur more than once.
  10.    """
  11.     return url + '?' + urllib.urlencode(data)
  12.  
  13. zipcode = 'S2S 7U8'
  14. url = addGETdata('http://www.wunderground.com/cgi-bin/findweather/getForecast',
  15.                  [('query', zipcode)])
  16. print "Using URL", url
  17. req = urllib2.Request(url)
  18. fd = urllib2.urlopen(req)
  19. while 1:
  20.     data = fd.read(1024)
  21.     if not len(data):
  22.         break
  23.     sys.stdout.write(data)
  24.  
  25. #//python/8088

回复 "python执行get提交的操作"

这儿你可以回复上面这条便签

captcha