mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
get_loc_from_str增加tag:tagName@arg=val方式
This commit is contained in:
parent
6e319dad80
commit
79bb8d4500
@ -4,6 +4,7 @@
|
|||||||
@Contact : g1879@qq.com
|
@Contact : g1879@qq.com
|
||||||
@File : common.py
|
@File : common.py
|
||||||
"""
|
"""
|
||||||
|
import re
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union
|
from typing import Union
|
||||||
@ -66,7 +67,12 @@ def get_loc_from_str(loc: str) -> tuple:
|
|||||||
by = loc_item[0]
|
by = loc_item[0]
|
||||||
loc_by = 'xpath'
|
loc_by = 'xpath'
|
||||||
if by == 'tag' and len(loc_item) == 2:
|
if by == 'tag' and len(loc_item) == 2:
|
||||||
loc_str = f'//{loc_item[1]}'
|
if '@' not in loc_item[1]:
|
||||||
|
loc_str = f'//{loc_item[1]}'
|
||||||
|
else:
|
||||||
|
r = re.search(r'(.*?)@([^=]*)=?(.*)', loc_item[1])
|
||||||
|
loc_str = f'//{r.group(1)}[@{r.group(2)}{"{}"}]'
|
||||||
|
loc_str = loc_str.format(f'="{r.group(3)}"') if r.group(3) else loc_str.format('')
|
||||||
elif by.startswith('@') and len(loc_item) == 2:
|
elif by.startswith('@') and len(loc_item) == 2:
|
||||||
loc_str = f'//*[{by}="{loc_item[1]}"]'
|
loc_str = f'//*[{by}="{loc_item[1]}"]'
|
||||||
elif by.startswith('@') and len(loc_item) == 1:
|
elif by.startswith('@') and len(loc_item) == 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user