原理讲解截图:
代码实现:
from urllib import parse
from datetime import datetime
import time
import requests
from loguru import logger
class DelayWait(object):
def __init__(self, delay=3):
"""
初始化定义睡眠时间,请求相同一个网站的url,睡眠为3秒
:param delay:
"""
self.delay = delay
self.urls = dict()
def wait(self, url):
"""
:param url:
:return:
"""
netloc = parse.urlparse(url).netloc#获取网站域名
last_one = self.urls.get(netloc)#判断当前访问url域名是否存在ÿ