Skip to content

Commit

Permalink
对每次请求前增加延迟,防止短期访问量过高被封ip
Browse files Browse the repository at this point in the history
  • Loading branch information
bobobo80 committed Nov 12, 2017
1 parent 8063b9e commit 6b11946
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Util/utilFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
-------------------------------------------------
"""
import requests
import time
from lxml import etree

from Util.LogHandler import LogHandler
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 6b11946

Please sign in to comment.