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])

  • 相关阅读:
    缺省源
    MySQL曹操外卖一
    MySQL曹操外卖二
    正确使用MySQL外键约束
    html大部分实用标签(结构型)
    html超级基础标签
    我的简单作业
    章节课程复习笔记
    FC超级玛丽研究(NES游戏)
    二维码生成
  • 原文地址:https://www.cnblogs.com/luoguoxing/p/14037749.html
Copyright © 2011-2022 走看看