diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index d96d013..1a18e89 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -12,4 +12,4 @@ from ._pages.chromium_page import ChromiumPage from ._pages.session_page import SessionPage from ._pages.web_page import WebPage -__version__ = '4.1.0.1' +__version__ = '4.1.0.2' diff --git a/DrissionPage/_elements/session_element.py b/DrissionPage/_elements/session_element.py index 5930a5b..d0cba7a 100644 --- a/DrissionPage/_elements/session_element.py +++ b/DrissionPage/_elements/session_element.py @@ -180,13 +180,14 @@ def make_session_ele(html_or_ele, loc=None, index=1, method=None): raise ValueError("定位符必须为str或长度为2的tuple。") # ---------------根据传入对象类型获取页面对象和lxml元素对象--------------- + the_type = getattr(html_or_ele, '_type', None) # 直接传入html文本 if isinstance(html_or_ele, str): page = None html_or_ele = fromstring(html_or_ele) # SessionElement - elif html_or_ele._type == 'SessionElement': + elif the_type == 'SessionElement': page = html_or_ele.owner loc_str = loc[1] @@ -207,7 +208,7 @@ def make_session_ele(html_or_ele, loc=None, index=1, method=None): loc = loc[0], loc_str - elif html_or_ele._type == 'ChromiumElement': + elif the_type == 'ChromiumElement': loc_str = loc[1] if loc[0] == 'xpath' and loc[1].lstrip().startswith('/'): loc_str = f'.{loc[1]}' @@ -230,7 +231,7 @@ def make_session_ele(html_or_ele, loc=None, index=1, method=None): html_or_ele = fromstring(html) html_or_ele = html_or_ele.xpath(xpath)[0] - elif html_or_ele._type == 'ChromiumFrame': + elif the_type == 'ChromiumFrame': page = html_or_ele html_or_ele = fromstring(html_or_ele.inner_html) diff --git a/DrissionPage/_functions/elements.py b/DrissionPage/_functions/elements.py index 17a372d..f559db2 100644 --- a/DrissionPage/_functions/elements.py +++ b/DrissionPage/_functions/elements.py @@ -309,6 +309,12 @@ def get_frame(owner, loc_ind_ele, timeout=None): raise TypeError('该定位符不是指向frame元素。') r = ele + elif isinstance(loc_ind_ele, int): + ele = owner._ele('@|tag():iframe@|tag():frame', timeout=timeout, index=loc_ind_ele) + if ele and ele._type != 'ChromiumFrame': + raise TypeError('该定位符不是指向frame元素。') + r = ele + elif getattr(loc_ind_ele, '_type', None) == 'ChromiumFrame': r = loc_ind_ele diff --git a/DrissionPage/_pages/mix_tab.py b/DrissionPage/_pages/mix_tab.py index b0d972b..72a46f2 100644 --- a/DrissionPage/_pages/mix_tab.py +++ b/DrissionPage/_pages/mix_tab.py @@ -100,6 +100,8 @@ class MixTab(SessionPage, ChromiumTab, BasePage): self.cookies_to_session() if timeout is None: kwargs['timeout'] = self.timeouts.page_load + if self._session is None: + self._create_session() super().post(url, show_errmsg, retry, interval, **kwargs) return self.response