@@ -118,7 +118,6 @@ def initEnv(self, env=None):
118118 self ._ENV = env
119119 self .t4_api = env .get ('proxyUrl' )
120120
121-
122121 def getProxyUrl (self ):
123122 """
124123 获取本地代理地址
@@ -147,12 +146,12 @@ def regStr(self, src, reg, group=1):
147146 return src
148147
149148 def custom_RegexGetText (self , Text , RegexText , Index , find_all = False ):
150- """改进版:支持返回所有匹配结果或单个匹配"""
151- if not find_all :
152- match = re .search (RegexText , Text , re .M | re .S )
153- return match .group (Index ) if match else ""
154- else :
155- return [m .group (Index ) for m in re .finditer (RegexText , Text , re .M | re .S )]
149+ """改进版:支持返回所有匹配结果或单个匹配"""
150+ if not find_all :
151+ match = re .search (RegexText , Text , re .M | re .S )
152+ return match .group (Index ) if match else ""
153+ else :
154+ return [m .group (Index ) for m in re .finditer (RegexText , Text , re .M | re .S )]
156155
157156 # cGroup = re.compile('[\U00010000-\U0010ffff]')
158157 # clean = cGroup.sub('',rsp.text)
@@ -161,34 +160,38 @@ def cleanText(self, src):
161160 src )
162161 return clean
163162
164- def fetch (self , url , data = None , headers = {}, cookies = "" , timeout = 5 ):
165- if data is None :
166- data = {}
167- rsp = requests .get (url , params = data , headers = headers , cookies = cookies , timeout = timeout , verify = False )
163+ def fetch (self , url , params = None , headers = None , cookies = None , timeout = 5 , verify = True , allow_redirects = True ):
164+ rsp = requests .get (url , params = params , headers = headers , cookies = cookies , timeout = timeout , verify = verify ,
165+ allow_redirects = allow_redirects )
168166 rsp .encoding = 'utf-8'
169167 return rsp
170168
171- def post (self , url , data , headers = {}, cookies = {}, timeout = 5 ):
172- rsp = requests .post (url , data = data , headers = headers , cookies = cookies , timeout = timeout , verify = False )
169+ def post (self , url , data , headers = None , cookies = None , timeout = 5 , verify = True , allow_redirects = True ):
170+ rsp = requests .post (url , data = data , headers = headers , cookies = cookies , timeout = timeout , verify = verify ,
171+ allow_redirects = allow_redirects )
173172 rsp .encoding = 'utf-8'
174173 return rsp
175174
176- def postJson (self , url , json , headers = {}, cookies = {}, timeout = 5 ):
177- rsp = requests .post (url , json = json , headers = headers , cookies = cookies , timeout = timeout , verify = False )
175+ def postJson (self , url , json , headers = None , cookies = None , timeout = 5 , verify = True , allow_redirects = True ):
176+ rsp = requests .post (url , json = json , headers = headers , cookies = cookies , timeout = timeout , verify = verify ,
177+ allow_redirects = allow_redirects )
178178 rsp .encoding = 'utf-8'
179179 return rsp
180180
181- def postBinary (self , url , data : dict , boundary = None , headers = {}, cookies = {}, timeout = 5 ):
181+ def postBinary (self , url , data : dict , boundary = None , headers = None , cookies = None , timeout = 5 , verify = True ,
182+ allow_redirects = True ):
182183 if boundary is None :
183184 boundary = f'--dio-boundary-{ int (time .time ())} '
185+ if headers is None :
186+ headers = {}
184187 headers ['Content-Type' ] = f'multipart/form-data; boundary={ boundary } '
185- # print(headers)
186188 fields = []
187189 for key , value in data .items ():
188190 fields .append ((key , (None , value , None )))
189191 m = encode_multipart_formdata (fields , boundary = boundary )
190192 data = m [0 ]
191- rsp = requests .post (url , data = data , headers = headers , cookies = cookies , timeout = timeout , verify = False )
193+ rsp = requests .post (url , data = data , headers = headers , cookies = cookies , timeout = timeout , verify = verify ,
194+ allow_redirects = allow_redirects )
192195 rsp .encoding = 'utf-8'
193196 return rsp
194197
0 commit comments