• 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. CentOS 7从Python 2.7升级至Python3.6.1

    引言: CentOS是目前最为流行的Linux服务器系统,其默认的Python 2.x,但是根据python社区的规划,在不久之后,整个社区将向Python3迁移,且将不在支持Python2, 那该如 ...

  2. 【问题解决方案】之 cmd 窗口问题汇总

    cmd窗口C盘切不到其他盘的解决方案: 1.切换盘符,直接键入其他盘,如:>>D: (回车) 2.强行切换>>cd /d D: 或者 >>pushd C:

  3. jenkins+maven+tomcat集群发布

    jenkins+Gitlab+maven+tomcat实现自动集成.打包.部署 - 李栋94 - 博客园https://www.cnblogs.com/lidong94/p/7427923.html ...

  4. MySQL的SQL语句优化-group by语句的优化

    原文:http://bbs.landingbj.com/t-0-243202-1.html 默认情况下,MySQL排序所有GROUP BY col1, col2, ....,查询的方法如同在查询中指定 ...

  5. C#设计模式之6:抽象工厂模式

    前面分析了简单工厂模式和工厂方法模式,接着来看一下抽象工厂模式,他与工厂方法模式有一些相似的地方,也有不同的地方. 先来看一个不用工厂方法模式实现的订购披萨的代码: 对象依赖的问题:当你直接实例化一个 ...

  6. 2 Servlet 细节

    1 Servlet 配置详解 ①  由于客户端在浏览器只能通过URL访问web服务器的资源,所以Servlet程序若想被外界访问,必须把Servlet 程序映射到一个URL 地址上,这个工作在项目we ...

  7. Java 基本数据类型 及 == 与 equals 方法的区别

    Java数据类型分为基本数据类型与引用数据类型. 1 基本数据类型 byte:Java中最小的数据类型,在内存中占1个字节(8 bit),取值范围-128~127,默认值0 short:短整型,2个字 ...

  8. mybatis出现NoSuchMethodException异常

    今天在idea中调试项目(ssm搭建的项目)的时候,mybatis突然出现了NoSuchMethodException异常,具体的异常时: java.lang.NoSuchMethodExceptio ...

  9. 使用withCount后再使用select设置查询的字段。就找不到withCount的数据了

    https://laravelacademy.org/index.php/discussion/1021 如:Article::withCount(['comments'])->select(' ...

  10. CentOS7配置gradle,或配置maven

    借鉴博客: https://www.cnblogs.com/imyalost/p/8746527.html 特简单,不多说了,自己看 1.下载gradle4.6版本:wget https://down ...