• 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. 使用 $(function(){}) 时遇到的一个小bug及解决方法

    在 $(function(){}) 中声明函数,在 $(function(){}) 外调函数,会报错 原因: 页面加载后,会先执行 $(function(){}) 外面的语句,再执行 $(functi ...

  2. IIS 日志导入到数据库的方法

    使用微软Log Parser 执行 logparser "SELECT * FROM d:\iislogs\u_ex18071705.log TO myTableName" -o: ...

  3. 海康威视笔试(C++)

    1. select和epoll的区别 2.服务器并发量之高性能服务器设计 3.SQL关键字 4.TCP乱序和重传的问题 5.c++对象内存分配问题 6.c++多线程 join的用法: Thread类的 ...

  4. Codeforces Round #486 (Div. 3)-C. Equal Sums

    C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. Sparse Principal Component Analysis via Regularized Low Rank Matrix Approximation(Adjusted Variance)

    目录 前言 文章概述 固定\(\widetilde{\mathrm{v}}\) 固定\(\widetilde{\mathrm{u}}\) Adjusted Variance 前言 这篇文章用的也是交替 ...

  6. java问题

    Collection 和 Collections的区别? Collection是集合类的上级接口,继承与他的接口主要有Set 和List. Collections是针对集合类的一个帮助类,他提供一系列 ...

  7. 环同态p64推论

    1.为什么属于f(x)∈f(I),那么 2.为什么x属于ker,那么f(x)属于f(I)?

  8. 运行Maven项目时出现invalid LOC header (bad signature)错误,Tomcat不能正常启动

    作为Maven小白,今天这问题困扰了我好久,经过多次在网上查询,终于找到了原因.明明一个小问题却耗费很多时间,着实不应该,所以必须记录一下. 报错信息如下: 对话框: 控制台: <span st ...

  9. 前端三大框架Angular & React & Vue

    前端三大框架: Angular[Google]:一套框架,多种平台移动端 & 桌面端.学会用Angular构建应用,然后把这些代码和能力复用在多种多种不同平台的应用上 —— Web.移动 We ...

  10. composer 自动加载 通过classmap自动架子啊

    https://github.com/brady-wang/composer github地址 composer加载自己写的类 放入一个目录下 更改composer.json "autolo ...