From a5e86167e275293153c5eb7e40f161d7badf3759 Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 13 Nov 2023 20:23:04 +0800 Subject: [PATCH] =?UTF-8?q?4.0.0b7=E5=BD=93set=5Fheadless(False)=E4=BD=86?= =?UTF-8?q?=E6=8E=A5=E7=AE=A1=E4=BA=86=E6=97=A0=E5=A4=B4=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=EF=BC=8C=E5=B0=86=E8=B5=B7=E5=85=B3=E9=97=AD=E5=B9=B6?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=96=B0=E7=9A=84=E6=9C=89=E5=A4=B4=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=EF=BC=9Bprop()=E6=94=B9=E7=94=A8js=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_commons/browser.py | 1 + DrissionPage/_elements/chromium_element.py | 13 +++++-------- DrissionPage/_pages/chromium_page.py | 2 -- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/DrissionPage/_commons/browser.py b/DrissionPage/_commons/browser.py index 76b8d67..dfd0ce1 100644 --- a/DrissionPage/_commons/browser.py +++ b/DrissionPage/_commons/browser.py @@ -76,6 +76,7 @@ def get_launch_args(opt): elif i.startswith('--headless'): if i == '--headless=false': headless = False + continue elif i == '--headless': i = '--headless=new' headless = True diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index 2d9d072..dcc0a4d 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -369,14 +369,11 @@ class ChromiumElement(DrissionElement): :param prop: 属性名 :return: 属性值文本 """ - p = self.page.run_cdp('Runtime.getProperties', objectId=self._obj_id)['result'] - for i in p: - if i['name'] == prop: - if 'value' not in i or 'value' not in i['value']: - return None - - value = i['value']['value'] - return format_html(value) if isinstance(value, str) else value + try: + value = self.run_js(f'return this.{prop};') + return format_html(value) if isinstance(value, str) else value + except: + return None def run_js(self, script, *args, as_expr=False): """对本元素执行javascript代码 diff --git a/DrissionPage/_pages/chromium_page.py b/DrissionPage/_pages/chromium_page.py index b201c83..e6aacc4 100644 --- a/DrissionPage/_pages/chromium_page.py +++ b/DrissionPage/_pages/chromium_page.py @@ -71,10 +71,8 @@ class ChromiumPage(ChromiumBase): ws = ws.json()['webSocketDebuggerUrl'].split('/')[-1] self._browser = Browser(self._driver_options.debugger_address, ws, self) - print(is_exist, self._driver_options._headless, self._browser.run_cdp('Browser.getVersion')['userAgent']) if (is_exist and self._driver_options._headless is False and 'headless' in self._browser.run_cdp('Browser.getVersion')['userAgent'].lower()): - print('aaa') self._browser.quit(3) connect_browser(self._driver_options) ws = get(f'http://{self._driver_options.debugger_address}/json/version', headers={'Connection': 'close'})