mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
默认只监听GET和POST请求;修复cookie设置expires问题
This commit is contained in:
parent
bf245f7221
commit
d7ec617988
@ -3,6 +3,7 @@
|
|||||||
@Author : g1879
|
@Author : g1879
|
||||||
@Contact : g1879@qq.com
|
@Contact : g1879@qq.com
|
||||||
"""
|
"""
|
||||||
|
from datetime import datetime
|
||||||
from html import unescape
|
from html import unescape
|
||||||
from http.cookiejar import Cookie
|
from http.cookiejar import Cookie
|
||||||
from re import sub
|
from re import sub
|
||||||
@ -250,7 +251,19 @@ def set_browser_cookies(page, cookies):
|
|||||||
cookie['expires'] = int(cookie['expiry'])
|
cookie['expires'] = int(cookie['expiry'])
|
||||||
cookie.pop('expiry')
|
cookie.pop('expiry')
|
||||||
if 'expires' in cookie:
|
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:
|
if cookie['value'] is None:
|
||||||
cookie['value'] = ''
|
cookie['value'] = ''
|
||||||
if cookie['name'].startswith('__Secure-'):
|
if cookie['name'].startswith('__Secure-'):
|
||||||
|
@ -43,11 +43,11 @@ class Listener(object):
|
|||||||
"""返回监听目标"""
|
"""返回监听目标"""
|
||||||
return self._targets
|
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 targets: 要匹配的数据包url特征,可用list等传入多个,为True时获取所有
|
||||||
:param is_regex: 设置的target是否正则表达式
|
:param is_regex: 设置的target是否正则表达式
|
||||||
:param method: 设置监听的请求类型,可用list等指定多个,为None时监听全部
|
:param method: 设置监听的请求类型,可指定多个,为None时监听全部
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
if targets is not None:
|
if targets is not None:
|
||||||
@ -68,11 +68,11 @@ class Listener(object):
|
|||||||
else:
|
else:
|
||||||
raise TypeError('method参数只能是str、list、tuple、set类型。')
|
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 targets: 要匹配的数据包url特征,可用list等传入多个,为True时获取所有
|
||||||
:param is_regex: 设置的target是否正则表达式
|
:param is_regex: 设置的target是否正则表达式
|
||||||
:param method: 设置监听的请求类型,可用list等指定多个,为None时监听全部
|
:param method: 设置监听的请求类型,可指定多个,为None时监听全部
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
if targets or method:
|
if targets or method:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user