mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
SessionPage删除timeout参数,未完成
This commit is contained in:
parent
9f49f874ca
commit
ac3a8ec27c
@ -317,9 +317,9 @@ class Browser(object):
|
||||
elif Settings.singleton_tab_obj:
|
||||
return id_or_num
|
||||
else:
|
||||
return self._get_tab(id_or_num.tab_id) # todo: 循环调用
|
||||
return self._get_tab(id_or_num.tab_id) # fixme: 这里会出现循环调用
|
||||
|
||||
elif title == url == tab_type is None:
|
||||
elif title == url is None and tab_type == 'page':
|
||||
id_or_num = self.tab_ids[0]
|
||||
|
||||
else:
|
||||
|
@ -38,12 +38,13 @@ __ERROR__ = 'error'
|
||||
class ChromiumBase(BasePage):
|
||||
"""标签页、frame、页面基类"""
|
||||
|
||||
def __init__(self, address, tab_id=None):
|
||||
def __init__(self, browser, tab_id=None):
|
||||
"""
|
||||
:param address: 浏览器 ip:port
|
||||
:param browser: Browser
|
||||
:param tab_id: 要控制的标签页id,不指定默认为激活的
|
||||
"""
|
||||
super().__init__()
|
||||
self._browser = browser
|
||||
self._is_loading = None
|
||||
self._root_id = None # object id
|
||||
self._set = None
|
||||
@ -64,19 +65,19 @@ class ChromiumBase(BasePage):
|
||||
if not hasattr(self, '_listener'):
|
||||
self._listener = None
|
||||
|
||||
if isinstance(address, int) or (isinstance(address, str) and address.isdigit()):
|
||||
address = f'127.0.0.1:{address}'
|
||||
# if isinstance(address, int) or (isinstance(address, str) and address.isdigit()):
|
||||
# address = f'127.0.0.1:{address}'
|
||||
|
||||
self._d_set_start_options(address)
|
||||
# self._d_set_start_options(address)
|
||||
self._d_set_runtime_settings()
|
||||
self._connect_browser(tab_id)
|
||||
|
||||
def _d_set_start_options(self, address):
|
||||
"""设置浏览器启动属性
|
||||
:param address: 'ip:port'
|
||||
:return: None
|
||||
"""
|
||||
self.address = address.replace('localhost', '127.0.0.1').lstrip('http://').lstrip('https://')
|
||||
# def _d_set_start_options(self, address):
|
||||
# """设置浏览器启动属性
|
||||
# :param address: 'ip:port'
|
||||
# :return: None
|
||||
# """
|
||||
# self.address = address.replace('localhost', '127.0.0.1').lstrip('http://').lstrip('https://')
|
||||
|
||||
def _d_set_runtime_settings(self):
|
||||
self._timeouts = Timeout(self)
|
||||
@ -90,7 +91,7 @@ class ChromiumBase(BasePage):
|
||||
self._is_reading = False
|
||||
|
||||
if not tab_id:
|
||||
tabs = self.browser._driver.get(f'http://{self.address}/json').json()
|
||||
tabs = self.browser._driver.get(f'http://{self.browser.address}/json').json()
|
||||
tabs = [(i['id'], i['url']) for i in tabs
|
||||
if i['type'] in ('page', 'webview') and not i['url'].startswith('devtools://')]
|
||||
dialog = None
|
||||
|
@ -31,12 +31,10 @@ PIC_TYPE = Literal['jpg', 'jpeg', 'png', 'webp', True]
|
||||
|
||||
class ChromiumBase(BasePage):
|
||||
def __init__(self,
|
||||
address: Union[str, int],
|
||||
browser: Browser,
|
||||
tab_id: str = None):
|
||||
self._browser: Browser = ...
|
||||
self._page: ChromiumPage = ...
|
||||
self.tab: Union[ChromiumPage, ChromiumTab] = ...
|
||||
self.address: str = ...
|
||||
self._driver: Driver = ...
|
||||
self._frame_id: str = ...
|
||||
self._is_reading: bool = ...
|
||||
@ -90,7 +88,7 @@ class ChromiumBase(BasePage):
|
||||
|
||||
def _wait_to_stop(self): ...
|
||||
|
||||
def _d_set_start_options(self, address) -> None: ...
|
||||
# def _d_set_start_options(self, address) -> None: ...
|
||||
|
||||
def _d_set_runtime_settings(self) -> None: ...
|
||||
|
||||
|
@ -28,7 +28,6 @@ class ChromiumFrame(ChromiumBase):
|
||||
:param info: frame所在元素信息
|
||||
"""
|
||||
self.tab = owner.tab
|
||||
self._browser = owner.browser
|
||||
self._target_page = owner
|
||||
# if owner._type in ('ChromiumPage', 'WebPage'):
|
||||
# self._target_page = self.tab = owner
|
||||
@ -39,8 +38,8 @@ class ChromiumFrame(ChromiumBase):
|
||||
# self._target_page = owner
|
||||
# self.tab = owner.tab if owner._type == 'ChromiumFrame' else owner
|
||||
|
||||
self.address = owner.address
|
||||
self._tab_id = owner.tab_id
|
||||
# self.address = owner.address
|
||||
# self._tab_id = owner.tab_id
|
||||
self._backend_id = ele._backend_id
|
||||
self._frame_ele = ele
|
||||
self._states = None
|
||||
@ -51,11 +50,11 @@ class ChromiumFrame(ChromiumBase):
|
||||
if self._is_inner_frame():
|
||||
self._is_diff_domain = False
|
||||
self.doc_ele = ChromiumElement(self._target_page, backend_id=node['contentDocument']['backendNodeId'])
|
||||
super().__init__(owner.address, owner.tab_id, owner.timeout)
|
||||
super().__init__(owner.browser, owner.tab_id)
|
||||
else:
|
||||
self._is_diff_domain = True
|
||||
delattr(self, '_frame_id')
|
||||
super().__init__(owner.address, node['frameId'], owner.timeout)
|
||||
super().__init__(owner.browser, node['frameId'])
|
||||
obj_id = super().run_js('document;', as_expr=True)['objectId']
|
||||
self.doc_ele = ChromiumElement(self, obj_id=obj_id)
|
||||
|
||||
@ -101,7 +100,7 @@ class ChromiumFrame(ChromiumBase):
|
||||
try:
|
||||
super()._driver_init(tab_id)
|
||||
except:
|
||||
self.browser.driver.get(f'http://{self.address}/json')
|
||||
self.browser._driver.get(f'http://{self._browser.address}/json')
|
||||
super()._driver_init(tab_id)
|
||||
self._driver.set_callback('Inspector.detached', self._onInspectorDetached, immediate=True)
|
||||
self._driver.set_callback('Page.frameDetached', None)
|
||||
@ -135,16 +134,16 @@ class ChromiumFrame(ChromiumBase):
|
||||
self.doc_ele = ChromiumElement(self._target_page, backend_id=node['contentDocument']['backendNodeId'])
|
||||
self._frame_id = node['frameId']
|
||||
if self._listener:
|
||||
self._listener._to_target(self._target_page.tab_id, self.address, self)
|
||||
super().__init__(self.address, self._target_page.tab_id, self._target_page.timeout)
|
||||
self._listener._to_target(self._target_page.tab_id, self._browser.address, self)
|
||||
super().__init__(self._browser, self._target_page.tab_id)
|
||||
# self.driver._debug = d_debug
|
||||
|
||||
else:
|
||||
self._is_diff_domain = True
|
||||
if self._listener:
|
||||
self._listener._to_target(node['frameId'], self.address, self)
|
||||
self._listener._to_target(node['frameId'], self._browser.address, self)
|
||||
end_time = perf_counter() + self.timeouts.page_load
|
||||
super().__init__(self.address, node['frameId'], self._target_page.timeout)
|
||||
super().__init__(self._browser, node['frameId'])
|
||||
timeout = end_time - perf_counter()
|
||||
if timeout <= 0:
|
||||
timeout = .5
|
||||
@ -323,7 +322,7 @@ class ChromiumFrame(ChromiumBase):
|
||||
@property
|
||||
def tab_id(self):
|
||||
"""返回frame所在tab的id"""
|
||||
return self._tab_id
|
||||
return self.tab.tab_id
|
||||
|
||||
@property
|
||||
def download_path(self):
|
||||
|
@ -28,9 +28,8 @@ class ChromiumFrame(ChromiumBase):
|
||||
owner: Union[ChromiumTab, ChromiumFrame],
|
||||
ele: ChromiumElement,
|
||||
info: dict = None):
|
||||
self._target_page: ChromiumBase = ...
|
||||
self._target_page: Union[ChromiumTab, ChromiumFrame] = ...
|
||||
self.tab: ChromiumTab = ...
|
||||
# self._tab_id: str = ...
|
||||
self._set: ChromiumFrameSetter = ...
|
||||
self._frame_ele: ChromiumElement = ...
|
||||
self._backend_id: int = ...
|
||||
|
@ -47,7 +47,7 @@ class ChromiumTab(ChromiumBase):
|
||||
|
||||
self.tab = self
|
||||
self._browser = browser
|
||||
super().__init__(browser.address, tab_id, browser.timeout)
|
||||
super().__init__(browser, tab_id)
|
||||
self._rect = None
|
||||
self._type = 'ChromiumTab'
|
||||
|
||||
|
@ -25,10 +25,9 @@ from .._units.setter import SessionPageSetter
|
||||
class SessionPage(BasePage):
|
||||
"""SessionPage封装了页面操作的常用功能,使用requests来获取、解析网页"""
|
||||
|
||||
def __init__(self, session_or_options=None, timeout=None):
|
||||
def __init__(self, session_or_options=None):
|
||||
"""
|
||||
:param session_or_options: Session对象或SessionOptions对象
|
||||
:param timeout: 连接超时时间(秒),为None时从ini文件读取或默认10
|
||||
"""
|
||||
super(SessionPage, SessionPage).__init__(self)
|
||||
self._headers = None
|
||||
@ -41,8 +40,6 @@ class SessionPage(BasePage):
|
||||
self._s_set_start_options(session_or_options)
|
||||
self._s_set_runtime_settings()
|
||||
self._create_session()
|
||||
if timeout is not None:
|
||||
self.timeout = timeout
|
||||
|
||||
def _s_set_start_options(self, session_or_options):
|
||||
"""启动配置
|
||||
|
@ -20,8 +20,7 @@ from .._units.setter import SessionPageSetter
|
||||
|
||||
class SessionPage(BasePage):
|
||||
def __init__(self,
|
||||
session_or_options: Union[Session, SessionOptions] = None,
|
||||
timeout: float = None):
|
||||
session_or_options: Union[Session, SessionOptions] = None):
|
||||
self._headers: Optional[CaseInsensitiveDict] = ...
|
||||
self._session: Session = ...
|
||||
self._session_options: SessionOptions = ...
|
||||
|
Loading…
x
Reference in New Issue
Block a user