Skip to content

Commit

Permalink
Merge pull request jhao104#85 from bobobo80/master
Browse files Browse the repository at this point in the history
 对每次请求前增加延迟,防止短期访问量过高被封ip
  • Loading branch information
jhao104 authored Nov 13, 2017
2 parents 640eba9 + 6b11946 commit 12cb720
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 12cb720

Please sign in to comment.