Selaa lähdekoodia

对每次请求前增加延迟,防止短期访问量过高被封ip

bobobo80 8 vuotta sitten
vanhempi
sitoutus
6b11946a82
1 muutettua tiedostoa jossa 5 lisäystä ja 0 poistoa
  1. 5 0
      Util/utilFunction.py

+ 5 - 0
Util/utilFunction.py

@@ -12,6 +12,7 @@
 -------------------------------------------------
 """
 import requests
+import time
 from lxml import etree
 
 from Util.LogHandler import LogHandler
@@ -63,6 +64,10 @@ def getHtmlTree(url, **kwargs):
               }
     # TODO 取代理服务器用代理服务器访问
     wr = WebRequest()
+
+    # delay 2s for per request
+    time.sleep(2)
+
     html = wr.get(url=url, header=header).content
     return etree.HTML(html)