添加代理设置,未完成

This commit is contained in:
g1879 2020-06-16 18:06:45 +08:00
parent b00c06ecde
commit 4497ee9fec
2 changed files with 17 additions and 11 deletions

View File

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

View File

@ -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"""
@ -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