diff --git a/DrissionPage/_base/browser.py b/DrissionPage/_base/browser.py index 7c8f0e9..35ed1f0 100644 --- a/DrissionPage/_base/browser.py +++ b/DrissionPage/_base/browser.py @@ -80,13 +80,13 @@ class Browser(object): def tabs_count(self): """返回标签页数量""" j = self.run_cdp('Target.getTargets')['targetInfos'] # 不要改用get,避免卡死 - return len([i for i in j if i['type'] == 'page']) + return len([i for i in j if i['type'] == 'page' and not i['url'].startswith('devtools://')]) @property def tabs(self): """返回所有标签页id组成的列表""" j = self._driver.get(f'http://{self.address}/json').json() # 不要改用cdp,因为顺序不对 - return [i['id'] for i in j if i['type'] == 'page'] + return [i['id'] for i in j if i['type'] == 'page' and not i['url'].startswith('devtools://')] @property def process_id(self): diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index 4a3da72..79a421d 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -10,8 +10,6 @@ from re import findall from threading import Thread from time import perf_counter, sleep -from requests import get - from .._base.base import BasePage from .._base.chromium_driver import ChromiumDriver from .._commons.constants import ERROR, NoneElement @@ -25,8 +23,8 @@ from .._units.network_listener import NetworkListener from .._units.screencast import Screencast from .._units.setter import ChromiumBaseSetter from .._units.waiter import ChromiumBaseWaiter -from ..errors import (ContextLossError, ElementLossError, CDPError, TabClosedError, NoRectError, BrowserConnectError, - AlertExistsError, GetDocumentError) +from ..errors import (ContextLossError, ElementLossError, CDPError, TabClosedError, NoRectError, AlertExistsError, + GetDocumentError) class ChromiumBase(BasePage): @@ -84,11 +82,7 @@ class ChromiumBase(BasePage): self._scroll = None if not tab_id: - json = get(f'http://{self.address}/json', headers={'Connection': 'close'}).json() - tab_id = [i['id'] for i in json if i['type'] == 'page'] - if not tab_id: - raise BrowserConnectError('浏览器连接失败,可能是浏览器版本原因。') - tab_id = tab_id[0] + tab_id = self.browser.tabs[0] self._driver_init(tab_id) if self.ready_state == 'complete' and self._ready_state is None: diff --git a/DrissionPage/_units/clicker.py b/DrissionPage/_units/clicker.py index c075d35..9a8659a 100644 --- a/DrissionPage/_units/clicker.py +++ b/DrissionPage/_units/clicker.py @@ -32,7 +32,7 @@ class Clicker(object): :param timeout: 模拟点击的超时时间,等待元素可见、不被遮挡、进入视口 :return: 是否点击成功 """ - if not by_js: + if not by_js: # 模拟点击 try: self._ele.scroll.to_see() can_click = False @@ -65,7 +65,6 @@ class Clicker(object): return True if Settings.raise_when_click_failed: raise CanNotClickError - return False def right(self):