我是靠谱客的博主 诚心店员,这篇文章主要介绍请求头,cookie转字典,时间戳转时间headers转字典(传递复制的header字符串)cookie转字典(传递cookie值)获取毫秒级时间戳获取秒级时间戳毫秒级时间戳转时间(10位的话去掉除1000)时间转时间戳,现在分享给大家,希望可以做个参考。

headers转字典(传递复制的header字符串)

def headers_to_dict(headers):
    row_headear = headers.split('n')
    row_dict = dict()
    for i in row_headear:
        if i == '':
            continue
        row = i.strip().split(':', 1)
        if len(row) == 0:
            continue
        if row[0] == '':
            continue
        row_dict[row[0].strip()] = row[1].strip()
    return row_dict

cookie转字典(传递cookie值)

def cookie_to_dict(cookies):
    row_cookie = cookies.split(';')
    row_dict = dict()
    for i in row_cookie:
        if i == '':
            continue
        row = i.strip().split('=', 1)
        row_dict[row[0].strip()] = row[1].strip()
    return row_dict

获取毫秒级时间戳

def get_stamp():
    """
    获取毫秒级时间戳
    :return:
    """
    stamp_time = int((time.time()) * 1000)
    return stamp_time

获取秒级时间戳

def get_s_stamp():
    """
    获取秒级时间戳
    :return:
    """
    stamp_time = int((time.time()) * 1000)
    return stamp_time

毫秒级时间戳转时间(10位的话去掉除1000)

def stamp_to_time(stamp_time):
    """
    时间戳转时间
    :return:
    """
    timeArray = time.localtime(stamp_time/1000)
    otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
    return otherStyleTime

时间转时间戳

def unix_time(dt):
    # 转换成时间数组
    timeArray = time.strptime(dt, "%Y-%m-%d")
    # 转换成时间戳
    timestamp = int(time.mktime(timeArray))
    return timestamp

在这里插入图片描述

最后

以上就是诚心店员最近收集整理的关于请求头,cookie转字典,时间戳转时间headers转字典(传递复制的header字符串)cookie转字典(传递cookie值)获取毫秒级时间戳获取秒级时间戳毫秒级时间戳转时间(10位的话去掉除1000)时间转时间戳的全部内容,更多相关请求头,cookie转字典,时间戳转时间headers转字典(传递复制内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部