From 03378136c4ce1be8c342058ac7dc7431bc1b1c09 Mon Sep 17 00:00:00 2001 From: g1879 Date: Sun, 4 Feb 2024 14:18:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AAjs=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_elements/chromium_element.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index 7442ace..5f6c62a 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -1447,7 +1447,10 @@ def run_js(page_or_ele, script, as_expr, timeout, args=None): try: return parse_js_result(page, page_or_ele, res.get('result'), end_time) except Exception: - return res + from DrissionPage import __version__ + raise RuntimeError(f'\njs结果解析错误\n内容:{res.get("result")}\n版本:{__version__}\n' + f'出现这个错误可能意味着程序有bug,请把错误信息和重现方法告知作者,谢谢。\n' + f'报告网站:https://gitee.com/g1879/DrissionPage/issues') def parse_js_result(page, ele, result, end_time): @@ -1475,11 +1478,7 @@ def parse_js_result(page, ele, result, end_time): elif sub_type == 'array': r = page.run_cdp('Runtime.getProperties', objectId=result['objectId'], ownProperties=True)['result'] - return [parse_js_result(page, ele, result=i['value'], end_time=end_time) for i in r[:-1]] - - elif 'objectId' in result and result['className'].lower() == 'object': # dict - r = page.run_cdp('Runtime.getProperties', objectId=result['objectId'], ownProperties=True)['result'] - return {i['name']: parse_js_result(page, ele, result=i['value'], end_time=end_time) for i in r} + return [parse_js_result(page, ele, result=i['value'], end_time=end_time) for i in r if i['name'].isdigit()] elif 'objectId' in result: timeout = end_time - perf_counter()