diff --git a/DrissionPage/mix_page.py b/DrissionPage/mix_page.py index c06cec7..fafb624 100644 --- a/DrissionPage/mix_page.py +++ b/DrissionPage/mix_page.py @@ -5,8 +5,6 @@ @File : mix_page.py """ from typing import Union, List -from urllib import parse -from urllib.parse import quote from requests import Response from requests_html import HTMLSession @@ -47,6 +45,7 @@ class MixPage(Null, SessionPage, DriverPage): self._driver = None self._url = None self._response = None + self._proxies = None self.timeout = timeout self._url_available = None self._mode = mode @@ -155,11 +154,10 @@ class MixPage(Null, SessionPage, DriverPage): # ----------------重写SessionPage的函数----------------------- - def post(self, url: str, params: dict = None, data: dict = None, go_anyway: bool = False, **kwargs) \ - -> Union[bool, None]: + def post(self, url: str, data: dict = None, go_anyway: bool = False, **kwargs) -> Union[bool, None]: """post前先转换模式,但不跳转""" self.change_mode('s', go=False) - return super().post(url, params, data, go_anyway, **kwargs) + return super().post(url, data, go_anyway, **kwargs) # ----------------重写DriverPage的函数----------------------- @@ -182,9 +180,6 @@ class MixPage(Null, SessionPage, DriverPage): def get(self, url: str, go_anyway=False, **kwargs) -> Union[bool, None]: """跳转到一个url,跳转前先同步cookies,跳转后判断目标url是否可用""" - # to_url = quote(url, safe='/:&?=%;#@') - # if not url or (not go_anyway and self.url == to_url): - # return if self._mode == 'd': if super(SessionPage, self).get(url=url, go_anyway=go_anyway) is None: return diff --git a/DrissionPage/session_page.py b/DrissionPage/session_page.py index 5de4976..c90e63d 100644 --- a/DrissionPage/session_page.py +++ b/DrissionPage/session_page.py @@ -29,6 +29,7 @@ class SessionPage(object): self._url = None self._url_available = None self._response = None + self._proxies = None @property def session(self) -> HTMLSession: @@ -53,6 +54,14 @@ class SessionPage(object): """当前session的cookies""" return self.session.cookies.get_dict() + @property + def proxies(self) -> dict: + return self._proxies + + @proxies.setter + def proxies(self, value: dict): + self._proxies = value + @property def title(self) -> str: """获取网页title""" @@ -85,7 +94,7 @@ class SessionPage(object): """查找符合条件的所有元素""" return self.ele(loc, mode='all', show_errmsg=True) - def get(self, url: str, go_anyway: bool = False, **kwargs) -> Union[bool, None]: + def get(self, url: str, go_anyway: bool = False, **kwargs) -> Union[bool, None]: """用get方式跳转到url,调用_make_response()函数生成response对象""" to_url = quote(url, safe='/:&?=%;#@') if not url or (not go_anyway and self.url == to_url): @@ -97,8 +106,7 @@ class SessionPage(object): self._url_available = True if self._response and self._response.ok else False return self._url_available - def post(self, url: str, data: dict = None, go_anyway: bool = False, **kwargs) \ - -> Union[bool, None]: + def post(self, url: str, data: dict = None, go_anyway: bool = False, **kwargs) -> Union[bool, None]: """用post方式跳转到url,调用_make_response()函数生成response对象""" to_url = quote(url, safe='/:&?=%;#@') if not url or (not go_anyway and self._url == to_url): @@ -209,6 +217,9 @@ class SessionPage(object): if self._url: kwargs['headers']['Referer'] = self._url + if 'proxies' not in kwargs_set and self._proxies: + kwargs['proxies'] = self.proxies + if 'timeout' not in kwargs_set: kwargs['timeout'] = self.timeout