完成s_ele()

This commit is contained in:
g1879 2021-11-20 22:50:21 +08:00
parent bab4461b58
commit 2552142782
5 changed files with 21 additions and 7 deletions

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from .drission import Drission

View File

@ -23,6 +23,8 @@ class OptionsManager(object):
:param path: ini文件的路径默认读取模块文件夹下的
"""
self.ini_path = str(Path(__file__).parent / 'configs.ini') if path == 'default' or path is None else path
if not Path(self.ini_path).exists():
raise FileNotFoundError('ini文件不存在。')
self._conf = RawConfigParser()
self._conf.read(self.ini_path, encoding='utf-8')

View File

@ -43,7 +43,7 @@ class DriverElement(DrissionElement):
:param timeout: 超时时间
:return: DriverElement对象或属性文本
"""
return super().__call__(loc_or_str, mode, timeout)
return self.ele(loc_or_str, mode, timeout)
# -----------------共有属性和方法-------------------
@property
@ -697,9 +697,9 @@ class Select(object):
if ele.tag != 'select':
raise TypeError(f"select方法只能在<select>元素使用,现在是:{ele.tag}")
from selenium.webdriver.support.select import Select as sl
from selenium.webdriver.support.select import Select
self.inner_ele = ele
self.select_ele = sl(ele.inner_ele)
self.select_ele = Select(ele.inner_ele)
def __call__(self,
text_value_index: Union[str, int, list, tuple] = None,

View File

@ -222,11 +222,12 @@ class SessionElement(DrissionElement):
def make_session_ele(html_or_ele: Union[str, BaseElement, BasePage],
loc: Union[str, Tuple[str, str]],
loc: Union[str, Tuple[str, str]] = None,
mode: str = 'single', ) -> Union[SessionElement, List[SessionElement], str, None]:
"""从接收到的对象或html文本中查找元素返回SessionElement对象 \n
如要直接从html生成SessionElement而不在下级查找loc输入None即可 \n
:param html_or_ele: html文本BaseParser对象
:param loc: 定位元组或字符串
:param loc: 定位元组或字符串为None时不在下级查找返回根元素
:param mode: 'single' 'all'对应获取第一个或全部
:return: 返回SessionElement元素或列表或属性文本
"""
@ -256,7 +257,10 @@ def make_session_ele(html_or_ele: Union[str, BaseElement, BasePage],
raise TypeError('html_or_ele参数只能是元素、页面对象或html文本。')
# ---------------处理定位符---------------
if isinstance(loc, str):
if not loc:
loc = ('xpath', '.')
mode = 'single'
elif isinstance(loc, str):
loc = str_to_loc(loc)
elif isinstance(loc, tuple):
loc = translate_loc(loc)

9
DrissionPage/tools.py Normal file
View File

@ -0,0 +1,9 @@
# -*- coding:utf-8 -*-
"""
实用工具
"""
from .session_element import make_session_ele
from .easy_set import get_match_driver
# TODO: 保存cookies到文件
# TODO: 从文件读取cookies