diff --git a/jd_assistant.py b/jd_assistant.py index 1282838..eeb17c3 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -641,6 +641,19 @@ def get_item_price(self, sku_id): resp = self.sess.get(url=url, params=payload) return parse_json(resp.text).get('p') + def get_item_info(self, sku_id): + resp = self._get_item_detail_page(sku_id) + soup = BeautifulSoup(resp.text, "html.parser") + name = get_tag_value(soup.select("div.sku-name")) + price = self.get_item_price(sku_id) + return {'name':name,'price':price} + + def print_item_info(self, sku_id): + item_info = self.get_item_info(sku_id) + print("商品名称:",item_info.get('name')) + print("商品价格:",item_info.get('price')) + + @check_login def add_item_to_cart(self, sku_ids): """添加商品到购物车 @@ -1324,6 +1337,13 @@ def exec_seckill(self, sku_id, retry=4, interval=4, num=1): logger.info('执行结束,抢购%s失败!', sku_id) return False + def get_sys_para(self, sku_id): + """自动获取系统参数""" + self.add_item_to_cart(sku_ids=sku_id) # 根据商品id添加购物车 + self.get_checkout_page_detail() + self.track_id = self.sess.cookies['TrackID'] + + def exec_seckill_by_time(self, sku_ids, buy_time, retry=4, interval=4, num=1): """定时抢购 :param sku_ids: 商品id,多个商品id用逗号进行分割,如"123,456,789" diff --git a/mainV2.py b/mainV2.py index f17bb81..e8198d5 100644 --- a/mainV2.py +++ b/mainV2.py @@ -17,6 +17,7 @@ if model_type == '1': print("定时预约抢购...") sku_id = input("请输入一个sku_id:") + asst.print_item_info(sku_id) reserve_info = asst.get_reserve_info(sku_id) reserve_time = reserve_info.get("yueStime") buy_time = reserve_info.get("qiangStime") @@ -36,7 +37,7 @@ print('获取抢购时间失败') buy_time = input("请输入抢购时间(2020-03-04 00:59:59.000):") #asst.exec_reserve_seckill_by_time(sku_id=sku_id,buy_time=time, retry=10, interval=1,num=1) - asst.exec_seckill_by_time(sku_ids=sku_id,buy_time=buy_time, retry=15, interval=1,num=1) + asst.exec_seckill_by_time(sku_ids=sku_id,buy_time=buy_time, retry=15, interval=0.2,num=1) elif model_type == '2': print("正常有货购买...") sku_ids = input("请输入一个或多个sku_id:")