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
