Skip to content

Commit f4c8f27

Browse files
authored
use any() to valid response content
1 parent 12cb720 commit f4c8f27

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

Util/WebRequest.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,8 @@ def get(self, url, header=None, retry_time=5, timeout=30,
7070
while True:
7171
try:
7272
html = requests.get(url, headers=headers, timeout=timeout)
73-
# if filter(lambda key: key in html.content, retry_flag):
74-
# 原filter语句执行if判断所有情况均为True情况,python3与python2的区别?
75-
# python3中filter返回filter对象,即使为空,if会判断为True
76-
# python2中filter返回list对象,为空,if判断为False
77-
for f in retry_flag:
78-
if f in html.content:
79-
raise Exception
73+
if any(f in html.content for f in retry_flag):
74+
raise Exception
8075
return html
8176
except Exception as e:
8277
print(e)

0 commit comments

Comments
 (0)