默认只监听GET和POST请求;修复cookie设置expires问题

This commit is contained in:
g1879 2023-12-05 22:34:09 +08:00
parent bf245f7221
commit d7ec617988
2 changed files with 18 additions and 5 deletions

View File

@ -3,6 +3,7 @@
@Author : g1879
@Contact : g1879@qq.com
"""
from datetime import datetime
from html import unescape
from http.cookiejar import Cookie
from re import sub
@ -250,7 +251,19 @@ def set_browser_cookies(page, cookies):
cookie['expires'] = int(cookie['expiry'])
cookie.pop('expiry')
if 'expires' in cookie:
cookie['expires'] = int(cookie['expires'])
if cookie['expires'].isdigit():
cookie['expires'] = int(cookie['expires'])
elif cookie['expires'].replace('.', '').isdigit():
cookie['expires'] = float(cookie['expires'])
else:
try:
cookie['expires'] = datetime.strptime(cookie['expires'],
'%a, %d %b %Y %H:%M:%S GMT').timestamp()
except ValueError:
cookie['expires'] = datetime.strptime(cookie['expires'],
'%a, %d %b %y %H:%M:%S GMT').timestamp()
if cookie['value'] is None:
cookie['value'] = ''
if cookie['name'].startswith('__Secure-'):

View File

@ -43,11 +43,11 @@ class Listener(object):
"""返回监听目标"""
return self._targets
def set_targets(self, targets=True, is_regex=False, method=None):
def set_targets(self, targets=True, is_regex=False, method=('GET', 'POST')):
"""指定要等待的数据包
:param targets: 要匹配的数据包url特征可用list等传入多个为True时获取所有
:param is_regex: 设置的target是否正则表达式
:param method: 设置监听的请求类型用list等指定多个为None时监听全部
:param method: 设置监听的请求类型指定多个为None时监听全部
:return: None
"""
if targets is not None:
@ -68,11 +68,11 @@ class Listener(object):
else:
raise TypeError('method参数只能是str、list、tuple、set类型。')
def start(self, targets=None, is_regex=False, method=None):
def start(self, targets=None, is_regex=False, method=('GET', 'POST')):
"""拦截目标请求,每次拦截前清空结果
:param targets: 要匹配的数据包url特征可用list等传入多个为True时获取所有
:param is_regex: 设置的target是否正则表达式
:param method: 设置监听的请求类型用list等指定多个为None时监听全部
:param method: 设置监听的请求类型指定多个为None时监听全部
:return: None
"""
if targets or method: