eles筛选增加attr();set.cookies()只支持;分隔cookies;

This commit is contained in:
g1879 2024-06-07 17:36:07 +08:00
parent 6624c2651a
commit 40dd6290d1
3 changed files with 22 additions and 6 deletions

View File

@ -307,6 +307,18 @@ class ElementsList(list):
r.append(i)
return r
def attr(self, name, value):
"""返回所有拥有某个attribute值的元素
:param name: 属性名称
:param value: 属性值
:return: 筛选结果
"""
r = ElementsList()
for i in self:
if i.attr(name) == value:
r.append(i)
return r
def _any_state(self, name, is_not=False):
"""
:param name: 状态名称

View File

@ -78,4 +78,6 @@ class ElementsList(list):
def property(self, name: str, value: str) -> List[ChromiumElement]: ...
def attr(self, name: str, value: str) -> List[ChromiumElement]: ...
def _any_state(self, name: str, is_not: bool = False) -> List[ChromiumElement]: ...

View File

@ -213,12 +213,14 @@ def cookies_to_tuple(cookies):
elif isinstance(cookies, str):
c_dict = {}
r = match(r'.*?=([^=]+)=', cookies)
if not r: # 只有一个
cookies = [cookies.rstrip(',;')]
else:
s = match(r'.*([,;]).*', r.group(1)).group(1)
cookies = cookies.rstrip(s).split(s)
cookies = cookies.rstrip('; ')
cookies = cookies.split(';')
# r = match(r'.*?=([^=]+)=', cookies)
# if not r: # 只有一个
# cookies = [cookies.rstrip(',;')]
# else:
# s = match(r'.*([,;]).*', r.group(1)).group(1)
# cookies = cookies.rstrip(s).split(s)
for attr in cookies:
attr_val = attr.strip().split('=', 1)