python使用post提交数据到远程url的方法

yipeiwu_com6年前Python基础

本文实例讲述了python使用post提交数据到远程url的方法。分享给大家供大家参考。具体如下:

import sys, urllib2, urllib
zipcode = "S2S 1R8"
url = 'http://www.yoursiteweb.com/getForecast'
data = urllib.urlencode([('query', zipcode)])
req = urllib2.Request(url)
fd = urllib2.urlopen(req, data)
while 1:
  data = fd.read(1024)
  if not len(data):
    break
  sys.stdout.write(data)

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python中mechanize库的简单使用示例

复制代码 代码如下:#!/usr/bin/env/ python#coding=utf-8import mechanizeimport cookielib # Cookie Jarcj...

python字符串与url编码的转换实例

主要应用的场景 爬虫生成带搜索词语的网址 1.字符串转为url编码 import urllib poet_name = "李白" url_code_name = urllib.quo...

用Python中的__slots__缓存资源以节省内存开销的方法

用Python中的__slots__缓存资源以节省内存开销的方法

我们曾经提到,Oyster.com的Python web服务器怎样利用一个巨大的Python dicts(hash table),缓存大量的静态资源。我们最近在Image类中,用仅仅一行...

python学习之编写查询ip程序

python学习之编写查询ip程序

公司服务器上的ip最少的也有100多个,有时候查到一个站的Ip, 不想通过OA去查,自己就用自己最近学的python知识,结合数据库,编写了一python小程序。实现只要输入主ip就能查...

解决webdriver.Chrome()报错:Message:'chromedriver' executable needs to be in Path

解决webdriver.Chrome()报错:Message:'chromedriver' executable needs to be in Path

'chromedriver' executable needs to be in Path 声明:本人萌新,刚学python不久记录一下自己的坑,发出来若能帮助到一些人尽早解决问题那便是...