Skip to content

Commit

Permalink
抢购之前输出商品信息,防止抢错商品
Browse files Browse the repository at this point in the history
  • Loading branch information
yilei committed Mar 9, 2020
1 parent ab0f690 commit 30f7dd0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions jd_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""添加商品到购物车
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion mainV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:")
Expand Down

0 comments on commit 30f7dd0

Please sign in to comment.