diff --git a/DrissionPage/configs/session_options.py b/DrissionPage/configs/session_options.py index eaa763b..8e32598 100644 --- a/DrissionPage/configs/session_options.py +++ b/DrissionPage/configs/session_options.py @@ -110,14 +110,23 @@ class SessionOptions(object): self._proxies = {} return self._proxies - def set_proxies(self, http, https=None): + def set_proxies(self, http=None, https=None): """设置proxies参数 :param http: http代理地址 :param https: https代理地址 :return: 返回当前对象 """ - proxies = None if http == https is None else {'http': http, 'https': https or http} - self._sets('proxies', proxies) + if isinstance(http, str): + if http.startswith('http://'): + http = http[7:] + elif http.startswith('https://'): + http = http[8:] + if isinstance(https, str): + if https.startswith('http://'): + https = https[7:] + elif http.startswith('https://'): + https = https[8:] + self._sets('proxies', {'http': http, 'https': https}) return self # ===========须独立处理的项结束============ diff --git a/DrissionPage/session_page.py b/DrissionPage/session_page.py index 20e1f04..71ccb88 100644 --- a/DrissionPage/session_page.py +++ b/DrissionPage/session_page.py @@ -366,14 +366,23 @@ class SessionPageSetter(object): """ self._page.session.headers['user-agent'] = ua - def proxies(self, http, https=None): + def proxies(self, http=None, https=None): """设置proxies参数 :param http: http代理地址 :param https: https代理地址 :return: None """ - proxies = None if http == https is None else {'http': http, 'https': https or http} - self._page.session.proxies = proxies + if isinstance(http, str): + if http.startswith('http://'): + http = http[7:] + elif http.startswith('https://'): + http = http[8:] + if isinstance(https, str): + if https.startswith('http://'): + https = https[7:] + elif https.startswith('https://'): + https = https[8:] + self._page.session.proxies = {'http': http, 'https': https} def auth(self, auth): """设置认证元组或对象 diff --git a/DrissionPage/session_page.pyi b/DrissionPage/session_page.pyi index c13d488..41bacd7 100644 --- a/DrissionPage/session_page.pyi +++ b/DrissionPage/session_page.pyi @@ -177,7 +177,7 @@ class SessionPageSetter(object): def user_agent(self, ua: str) -> None: ... - def proxies(self, http, https=None) -> None: ... + def proxies(self, http: str = None, https: str = None) -> None: ... def auth(self, auth: Union[Tuple[str, str], HTTPBasicAuth, None]) -> None: ...