Просмотр исходного кода

Merge pull request #58 from bobobo80/bobo_dev

WebRequest中的retry_flag filter判断
J_hao104 9 лет назад
Родитель
Сommit
ba2f983760
1 измененных файлов с 8 добавлено и 4 удалено
  1. 8 4
      Util/WebRequest.py

+ 8 - 4
Util/WebRequest.py

@@ -70,10 +70,14 @@ class WebRequest(object):
         while True:
             try:
                 html = requests.get(url, headers=headers, timeout=timeout)
-                if filter(lambda key: key in html.content, retry_flag):
-                    raise Exception
-                else:
-                    return html
+                # if filter(lambda key: key in html.content, retry_flag):
+                # 原filter语句执行if判断所有情况均为True情况,python3与python2的区别?
+                # python3中filter返回filter对象,即使为空,if会判断为True
+                # python2中filter返回list对象,为空,if判断为False
+                for f in retry_flag:
+                    if f in html.content:
+                        raise Exception
+                return html
             except Exception as e:
                 print(e)
                 retry_time -= 1