mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
完成s_ele()
This commit is contained in:
parent
bab4461b58
commit
2552142782
@ -1,4 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
from .drission import Drission
|
||||
|
@ -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')
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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
9
DrissionPage/tools.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user