• requests发送get请求
  1. 无参数的get请求:
 response = requests.get(url='http://ws.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince')
s = response.status_code

2.有参数的get请求

 url = 'http://ws.webxml.com.cn/WebServices//WeatherWS.asmx/getSupportCityString'
params= {'theRegionCode':3113}
response = requests.get(url = url,params=params)
  • requests发送post请求

 """
post请求常见的四种方式
1.application/x-www-form-urlencoded :最常见的post提交数据的方式,浏览器的原生<form>表单
2.form-data :一般用来上传文件
3.application/json :作为请求头,用来告诉服务端消息主体是序列化的JSON字符串
4.text/xml
"""
    1. 1.application/x-www-form-urlencoded
 url = 'http://ws.webxml.com.cn/WebServices//WeatherWS.asmx/getSupportCityString'
params = {'theRegionCode':3113}
response = requests.post(url=url,data=params,headers={'Content-Type':'application/x-www-form-urlencoded'})

2.text/xml

 url = 'http://ws.webxml.com.cn/WebServices/WeatherWS.asmx'
# 存入xml 为了保持文本格式
data = '''<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getSupportCityDataset xmlns="http://WebXml.com.cn/">
<theRegionCode>3113</theRegionCode>
</getSupportCityDataset>
</soap:Body>
</soap:Envelope>'''
response = requests.post(url=url,data=data,headers={'Content-Type':'application/json'})
print(response.text)

3.application/json

 url = 'http://139.199.132.220:8000/event/weather/getWeather/'
data = {"theCiryCode": 1}
response = requests.post(url=url,json=data,headers={'Content-Type':'text/xml'})
print(response.text)

4.form-data(表单提交)

 data = {'key1':'value1','key2':'value2'}
requests.post(url,data=data)

requests简单应用的更多相关文章

  1. python第三方库requests简单介绍

    一.发送请求与传递参数 简单demo: import requests r = requests.get(url='http://www.itwhy.org') # 最基本的GET请求 print(r ...

  2. 使用requests简单的页面爬取

    首先安装requests库和准备User Agent 安装requests直接使用pip安装即可 pip install requests 准备User Agent,直接在百度搜索"UA查询 ...

  3. Python第三方模块--requests简单使用

    1.requests简介 requests是什么?python语言编写的,基于urllib的第三方模块 与urllib有什么关系?urllib是python的内置模块,比urllib更加简洁和方便使用 ...

  4. python requests 简单实现易班登录,自动点赞,评论,发表

    小编能力有限,本文纯属瞎编,如有雷同,你去打辅导员涩 一.前戏 有个操蛋,操蛋,操蛋的辅导员促使小编成长,原因:易班需要活跃度,辅导员安排班上每个人必须去易班上 写文章,写评论,发投票...  我觉得 ...

  5. requests 简单应用

    http://docs.python-requests.org/zh_CN/latest/user/quickstart.html  ,官方文档.自己有空看看顺便敲两下熟悉一下. 还有别把文件放的太深 ...

  6. python requests简单接口自动化

    get方法 url:显而易见,就是接口的地址url啦 headers:定制请求头(headers),例如:content-type = application/x-www-form-urlencode ...

  7. Python爬虫从入门到进阶(3)之requests的使用

    快速上手(官网地址:http://www.python-requests.org/en/master/user/quickstart/) 发送请求 首先导入Requests模块 import requ ...

  8. Requests库使用总结

    概述 Requests是python中一个很Pythonic的HTTP库,用于构建HTTP请求与解析响应 Requests开发哲学 Beautiful is better than ugly.(美丽优 ...

  9. Python爬虫:requests 库详解,cookie操作与实战

    原文 第三方库 requests是基于urllib编写的.比urllib库强大,非常适合爬虫的编写. 安装: pip install requests 简单的爬百度首页的例子: response.te ...

随机推荐

  1. 从 0 到 1 实现 React 系列 —— 5.PureComponent 实现 && HOC 探幽

    本系列文章在实现一个 cpreact 的同时帮助大家理顺 React 框架的核心内容(JSX/虚拟DOM/组件/生命周期/diff算法/setState/PureComponent/HOC/...) ...

  2. Php7 开发笔记

    Ubuntu环境安装 http://www.jianshu.com/p/1d312d9f1be1 sudo apt-get install python-software-properties sof ...

  3. 第十二次oo作业

    作业十二 规格化设计简介 规格化设计的发展历史 1950年代,第一次分离,主程序与子程序的分离结构是树状模型,子程序可先于主程序编写.通过使用库函数来简化编程,实现最初的代码重用.产生基本的软件开发过 ...

  4. JSF生存指南P1

    这是OO的第三次博客作业,也是JSFO(面向JSF编程)的第一次博客作业.暗示了我们面向对象课程已经再向JSF的编写过渡. 不知不觉OO的作业已经写完3/4,那些熬夜赶作业的日子仍然历历在目,仿佛是昨 ...

  5. 软件工程(FZU2015) 学生博客列表(最终版)

    FZU:福州大学软件工程 张老师的博客:http://www.cnblogs.com/easteast/ 经过前两周选课,最后正式选上课程的所有学生博客如下: 序号 学号后3位 博客 1 629 li ...

  6. js基础语法之函数

    普通函数 function foo(a, b){ return a + b; } foo(10, 20) >>> 30 匿名函数 var f = function(){console ...

  7. linux系统下MySQL表名区分大小写问题

    linux系统下MySQL表名区分大小写问题 https://www.cnblogs.com/jun1019/p/7073227.html [mysqld] lower_case_table_name ...

  8. 获取环境变量,0x000000cb 操作系统找不到已输入的环境选项

    include "stdafx.h" #include <Windows.h> #include <iostream> #pragma warning(di ...

  9. Linux基础命令和NAT技术

    yum    yellowdog updater,modified是一种用python写的基于rpm的管理工具 用于解决rpm包的依赖性 要安装编译工具 yum install gcc 库函数:静态库 ...

  10. IdentityServer4【QuickStart】之使用ResourceOwnerPassword流程来保护API

    使用ResourceOwnerPassword流程来保护API OAuth2.0中的ResourceOwnerPassword授权流程允许一个客户端发送username和password到token服 ...