diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index 1e25da5..1c764c2 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -57,7 +57,7 @@ class ChromiumBase(BasePage): :param none: 用于后代继承 :return: None """ - self.address = address + self.address = address.replace('localhost', '127.0.0.1').lstrip('http://').lstrip('https://') def _set_runtime_settings(self): self._timeouts = Timeout(self) diff --git a/DrissionPage/chromium_page.py b/DrissionPage/chromium_page.py index 821bbb4..ca17a1e 100644 --- a/DrissionPage/chromium_page.py +++ b/DrissionPage/chromium_page.py @@ -57,7 +57,8 @@ class ChromiumPage(ChromiumBase): else: raise TypeError('只能接收ChromiumDriver或ChromiumOptions类型参数。') - self.address = self._driver_options.debugger_address + self.address = self._driver_options.debugger_address.replace('localhost', + '127.0.0.1').lstrip('http://').lstrip('https://') def _set_runtime_settings(self): """设置运行时用到的属性""" diff --git a/DrissionPage/commons/browser.py b/DrissionPage/commons/browser.py index 6033996..77c4c86 100644 --- a/DrissionPage/commons/browser.py +++ b/DrissionPage/commons/browser.py @@ -21,12 +21,11 @@ def connect_browser(option): :param option: DriverOptions对象 :return: chrome 路径和进程对象组成的元组 """ - debugger_address = option.debugger_address + debugger_address = option.debugger_address.replace('localhost', '127.0.0.1').lstrip('http://').lstrip('https://') chrome_path = option.browser_path - debugger_address = debugger_address[7:] if debugger_address.startswith('http://') else debugger_address ip, port = debugger_address.split(':') - if ip not in ('127.0.0.1', 'localhost'): + if ip != '127.0.0.1': test_connect(ip, port) return None, None diff --git a/DrissionPage/configs/chromium_options.py b/DrissionPage/configs/chromium_options.py index b7d619f..49f395b 100644 --- a/DrissionPage/configs/chromium_options.py +++ b/DrissionPage/configs/chromium_options.py @@ -115,6 +115,7 @@ class ChromiumOptions(object): @debugger_address.setter def debugger_address(self, address): """设置浏览器地址,格式ip:port""" + address = address.replace('localhost', '127.0.0.1').lstrip('http://').lstrip('https://') self._debugger_address = address @property @@ -313,7 +314,7 @@ class ChromiumOptions(object): self._auto_port = False if debugger_address is not None: - self._debugger_address = debugger_address + self.debugger_address = debugger_address if download_path is not None: self._download_path = str(download_path) diff --git a/DrissionPage/easy_set.py b/DrissionPage/easy_set.py index 640dbb2..044c22b 100644 --- a/DrissionPage/easy_set.py +++ b/DrissionPage/easy_set.py @@ -89,7 +89,8 @@ def set_paths(driver_path=None, om.set_item('chrome_options', 'debugger_address', f'127.0.0.1:{local_port}') if debugger_address is not None: - om.set_item('chrome_options', 'debugger_address', debugger_address) + address = debugger_address.replace('localhost', '127.0.0.1').lstrip('http://').lstrip('https://') + om.set_item('chrome_options', 'debugger_address', address) if download_path is not None: om.set_item('paths', 'download_path', format_path(download_path)) diff --git a/DrissionPage/web_page.py b/DrissionPage/web_page.py index 3c7aa2f..02dda53 100644 --- a/DrissionPage/web_page.py +++ b/DrissionPage/web_page.py @@ -83,7 +83,8 @@ class WebPage(SessionPage, ChromiumPage, BasePage): else: raise TypeError('driver_or_options参数只能接收ChromiumDriver, ChromiumOptions、None或False。') - self.address = self._driver_options.debugger_address + self.address = self._driver_options.debugger_address.replace('localhost', + '127.0.0.1').lstrip('http://').lstrip('https://') # Session配置 if isinstance(se_opt, Session):