• 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. 字典 dict

    # --------------------------我愿作一叶小舟,驶向远方.----------------------------------------------------------- ...

  2. 搜狐畅游一面(c++)

    上来是个小姐姐,有点懵.. 1.  介绍 2.  项目 3.  实习 4.  用的协议 tcp和udp的协议 5.  select 和epoll(忘了) 6. 数据库的隔离级别, 死锁, 怎么避免死锁 ...

  3. Diverse Garland CodeForces - 1108D (贪心+暴力枚举)

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  4. Echatrs 中PIE饼图中间位置怎么显示总数值?

    title: { text: '总资产', subtext: '2000000.00', x: 'center', y: 'center' }图例:

  5. Pair Project

    以前只是一个人完成一个项目,不论什么都是,现在突然要两个人一起来写, 听上去挺稀奇的,也挺简单的,可惜了就是“听上去”而已.我认为这也是一种技术啊~ 我跟我的搭档研究了好久好久,选择了好久,然后也选了 ...

  6. 福州大学软件工程1816 | W班 第1次作业成绩排名

    1.作业地址 第一次作业--准备篇 2.作业要求 (1)回想一下你初入大学时对计算机专业的畅想 当初你是如何做出选择计算机专业的决定的? 你认为过去两年中接触到的课程是否符合你对计算机专业的期待,为什 ...

  7. #Leetcode# 633. Sum of Square Numbers

    https://leetcode.com/problems/sum-of-square-numbers/ Given a non-negative integer c, your task is to ...

  8. 封装day.js

    封装day.js import dayjs from 'dayjs' import 'dayjs/locale/zh-cn' import relativeTime from 'dayjs/plugi ...

  9. Java.lang.OutOfMemoryError:Metaspace

    Understand the OutOfMemoryError Exceptionhttps://docs.oracle.com/javase/8/docs/technotes/guides/trou ...

  10. bootstrap 弹窗或者提示框插件 bootstrap-growl 和bootstrap-notify

    Bootstrap简单好用的页面右上角咆哮提示框 - daidaineteasy的专栏 - CSDN博客https://blog.csdn.net/daidaineteasy/article/deta ...