session的网址会自动去除http://和https://

This commit is contained in:
g1879 2023-06-02 21:40:33 +08:00
parent 94a544b731
commit fb580fda00
3 changed files with 25 additions and 7 deletions

View File

@ -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
# ===========须独立处理的项结束============

View File

@ -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):
"""设置认证元组或对象

View File

@ -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: ...