From 9d24bf908ba6c464b1c7a6f76276070bd4e8f53a Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 24 Apr 2023 14:57:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8iframe=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=85=83=E7=B4=A0s=5Fele()=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/session_element.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/DrissionPage/session_element.py b/DrissionPage/session_element.py index 03d085e..e7d375b 100644 --- a/DrissionPage/session_element.py +++ b/DrissionPage/session_element.py @@ -333,10 +333,9 @@ def make_session_ele(html_or_ele, loc=None, single=True): # 获取整个页面html再定位到当前元素,以实现查找上级元素 page = html_or_ele.page xpath = html_or_ele.xpath - if hasattr(html_or_ele, 'doc_id'): # ChromiumElement,兼容传入的元素在iframe内的情况 - html = html_or_ele.page.run_cdp('DOM.getOuterHTML', objectId=html_or_ele.doc_id)['outerHTML'] - else: - html = html_or_ele.page.html + # ChromiumElement,兼容传入的元素在iframe内的情况 + html = html_or_ele.page.run_cdp('DOM.getOuterHTML', objectId=html_or_ele.ids.doc_id)['outerHTML'] \ + if html_or_ele.ids.doc_id else html_or_ele.page.html html_or_ele = fromstring(html) html_or_ele = html_or_ele.xpath(xpath)[0]