diff --git a/Config/config.ini b/Config/config.ini index 591059d..b9587a2 100755 --- a/Config/config.ini +++ b/Config/config.ini @@ -12,8 +12,10 @@ amount = 1 buy_time = "2021-11-13 04:30:00.000" # 提交订单失败重试次数 retry = 100 -# 查询库存请求超时(秒),可选配置,默认10秒 -timeout = 10 +# 查询库存请求超时(秒),可选配置,默认30秒 +timeout = 30 +# 最大查询随机数,给查询请求加的随机间隔时间,默认5s +random_time = 5 # 默认UA DEFAULT_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" # 是否使用随机 useragent,默认为 False diff --git a/Core/spider.py b/Core/spider.py index 562a3cf..0299f81 100644 --- a/Core/spider.py +++ b/Core/spider.py @@ -29,6 +29,8 @@ class Waiter(): retry=config.settings("Spider", "retry"), work_count=config.settings( 'Spider', 'work_count'), + random_time=config.settings( + 'Spider', 'random_time'), timeout=float(config.raw( "Spider", "timeout")), date=config.settings('Spider', 'buy_time').__str__() @@ -42,6 +44,7 @@ class Waiter(): self.payment_pwd = payment_pwd self.retry = retry self.work_count = work_count + self.random_time = random_time self.timeout = timeout self.buyTime = date @@ -188,7 +191,7 @@ class Waiter(): else: logger.info("等待商品上架: {}".format( self.get_sku_title()[:80] + " ......")) - time.sleep(random.randint(1, 10)) + time.sleep(self.timeout + random.randint(1, self.random_time)) def _waitTimeForSell(self): self.initCart()