• 访问个人主页、蘑菇丁、使用:import urllib.request


    import ssl
    import json
    #使用urllib 去访问页面
    import urllib.request as ur
    #规避警告
    context = ssl._create_unverified_context()


    #登录函数
    def Login(info_data):

    # 把字典info_data转成字符串、再用过encoding指定的编码格式编码字符串
    test_data = json.dumps(info_data).encode()
    print("*******",test_data,"-----",type(test_data))

    request_data = ur.Request(
    #要登录的网址
    url='https://api.moguding.net:9000/session/user/v1/login',

    # info_data =是{'loginType': 'iphone', 'password': 'hope2019', 'phone': '18681989609'}
    #登录头中的数据
    data=json.dumps(info_data).encode(),

    #高速服务器自己是谁, 这里说自己是app
    headers={'Content-Type': 'application/json; charset=UTF-8'}
    )

    print(ur.Request)
    try:
    #实现登录 其中.read()是拿到内容, ,decode是以Python decode() 方法以 encoding 指定的编码格式解码字符串
    response = json.loads(ur.urlopen(request_data, context=context).read().decode())
    token = response['data']['token']

    #拿到token
    if token:
    return {
    'code': '200',
    'info': '登录成功',
    'token': token
    }

    except Exception as e:
    if str(e) == '<urlopen error Remote end closed connection without response>':
    return {
    'code': '404',
    'info': '网络链接超时'
    }
    else:
    return {
    'code': '505',
    'info': '账号或密码错误'
    }


    #个人中心
    def GetReports(token, reportType):
    ids = []
    day = {"currPage": 1, "pageSize": 25, "batchId": "", "classId": "",
    "teaId": "", "reportType": reportType, "planId": "", "state": 0}
    request_data = ur.Request(

    #个人中心的网址
    url = "https://api.moguding.net:9000/usercenter/user/v1/info",
    #url='https://api.moguding.net:9000/practice/paper/v1/list',
    headers={
    'Authorization': token,
    'Content-Type': 'application/json; charset=UTF-8'
    },
    data=json.dumps(day).encode("utf-8"))
    try:
    #访问个人中心、、
    response = ur.urlopen(request_data, context=context).read().decode()
    print("response--------------",response)
    #print("response---headers-----------", response.co)
    return response
    except Exception as e:
    print(e)


    if __name__ == '__main__':
    response = Login({'loginType': 'iphone', 'password': 'Jia25257758', 'phone': '18082539819'})
    token = response['token']
    print("打印token",token)
    ids = GetReports(token,"day")
    print("个人中心的response:", ids)
  • 相关阅读:
    nginx 优化
    linux 内核的优化
    Linux下如何查看版本
    oracle安装数据库中文乱码解决办法
    Python 5 行代码的神奇操作
    Python爬取网站上面的数据很简单,但是如何爬取APP上面的数据呢
    解放双手!用 Python 控制你的鼠标和键盘
    js混淆、eval解密
    ubuntu
    爬虫基本原理
  • 原文地址:https://www.cnblogs.com/yuanjia8888/p/13497322.html
Copyright © 2020-2023  润新知