zoukankan      html  css  js  c++  java
  • 【python】接口自动化初识第二站

    import re
    import requests
    import json
    import jsonpath
    # response=requests.get('http://www.hnxmxit.com/')
    # #响应状态码
    # print(response.status_code)
    # #响应信息
    # print(response.reason)
    # #响应头
    # print(response.headers)
    # #部分响应头
    # print(response.headers.get('Content-Type'))
    # #响应正文
    # # print(response.content.decode("utf-8"))
    # #获取部分响应正文(.+?)的含义:.表示一个字符,+表示匹配前面的子表达式一次或者多次,?表示懒惰字符,就近匹配原则
    # body=response.content.decode("utf-8")
    # title_value=re.findall('<title>(.+?)</title>',body)[0]
    # print(title_value)

    #带参数的get请求
    # get_param_dict={'grant_type':'client_credential',
    # 'appid':'wx55614004f367f8ca',
    # 'secret':'65515b46dd758dfdb09420bb7db2c67f'}
    # response02=requests.get(url='https://api.weixin.qq.com/cgi-bin/token',
    # params=get_param_dict)
    #获取json数据
    # print(response02.json())
    #获取部分json数据access_token
    # print(response02.json().get('access_token'))
    #把json数据导入token_id
    # token_id=response02.json().get('access_token')
    #用jsonpath的方法导入
    # token_id=jsonpath.jsonpath(response02.json(),'$.access_token')
    # print(response02.content.decode('utf-8'))
    #另一个接口导入上一个接口的token_id
    # get_param_dict_02={
    # 'access_token':token_id
    # }
    # response03=requests.get(url='https://api.weixin.qq.com/cgi-bin/tags/get',
    # params=get_param_dict_02)
    # print(response03.content.decode('utf-8'))
    #老方法获取json数据
    # print(response03.json()['tags'][2]['name'])
    #新方法获取json数据
    # value = jsonpath.jsonpath(response03.json(),'$.tags[2].name')
    # print(value[0])

  • 相关阅读:
    Idea打包问题
    centos问题总结
    Linux CentOS7 系统目录详解
    centos下修改文件后如何保存退出
    利用windows上的VMware安装CentOS7
    VMware安装系统出现Operating System not found 解决方案
    mybatis 0 变成null问题
    Shiro权限前端调用302重定向
    java版本
    产品画原型工具放入到托管平台
  • 原文地址:https://www.cnblogs.com/luoguoxing/p/14037749.html
Copyright © 2011-2022 走看看