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'})