python執(zhí)行get提交的方法
更新時間:2015年04月29日 10:02:40 作者:重負在身
這篇文章主要介紹了python執(zhí)行get提交的方法,實例分析了Python通過get傳遞數(shù)據(jù)的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了python執(zhí)行get提交的方法。分享給大家供大家參考。具體如下:
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程序設計有所幫助。
相關文章
Python常用模塊之threading和Thread模塊及線程通信
這篇文章主要介紹了Python常用模塊之threading和Thread模塊及線程通信,文章為圍繞主題的相關內(nèi)容展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的朋友看可以參考一下方法2022-06-06使用virtualenv創(chuàng)建Python環(huán)境及PyQT5環(huán)境配置的方法
這篇文章主要介紹了使用virtualenv創(chuàng)建Python環(huán)境及PyQT5環(huán)境配置的方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-09-09