国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

python - How to add time or speed control when traversing a list?
天蓬老師
天蓬老師 2017-06-14 10:53:10
0
2
853
def dateRange(start, end, step=1, format="%Y-%m-%d"):
    strptime, strftime = datetime.datetime.strptime, datetime.datetime.strftime
    days = (strptime(end, format) - strptime(start, format)).days
    return [strftime(strptime(start, format) + datetime.timedelta(i), format) for i in xrange(0, days, step)]
ef weekend():
    try:
        dayday = dateRange(st, ed)

        for day in dayday:
            d =day.replace('-','')
            date = d
            server_url = "http://www.easybots.cn/api/holiday.php?d="

            vop_url_request = urllib2.Request(server_url + date)
            vop_response = urllib2.urlopen(vop_url_request)

            vop_data = json.loads(vop_response.read())

            if vop_data[date] == '1' or vop_data[date] == '2':
                dayday.remove(day)

        return dayday

    except:
        dayday = dateRange(st, ed)
        return dayday

There is such a weekend function to request some content, but some content will be missing every time it is executed. It is suspected to be a problem with the network speed. How to limit the frequency of traversal or access once in a few seconds?

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進(jìn)步~~

reply all(2)
typecho

After each iteration, add a sleep time

time.sleep(1) # 睡眠1秒

That is, your code can be adjusted to:

for day in dayday:
    ...(訪問(wèn)處理代碼)
    time.sleep(1)
    
學(xué)習(xí)ing

I found the problem. The remove operation on the original list during traversal will change the length of the list, which will lead to misalignment of the list. The final result is not the desired result

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template