From 690ca22cbf9afb5aa7a539dbcabced4506501fd8 Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Thu, 22 Jul 2021 20:50:30 +0800 Subject: [PATCH 01/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6a1fa0..cebd7c2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) [![star, issue](https://img.shields.io/badge/star%2C%20issue-welcome-brightgreen.svg)](https://github.com/tychxn/jd-assistant) -京东抢购助手(短期内不再更新) +京东抢购助手-由于原作者已不再更新、刚好我又有需要、所以在此基础上进行了修改; ## 主要功能 From f18804f7a6bcca5a39c585472bc30fe66e41e28d Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Thu, 22 Jul 2021 20:54:18 +0800 Subject: [PATCH 02/23] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cebd7c2..f67493e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) [![star, issue](https://img.shields.io/badge/star%2C%20issue-welcome-brightgreen.svg)](https://github.com/tychxn/jd-assistant) -京东抢购助手-由于原作者已不再更新、刚好我又有需要、所以在此基础上进行了修改; +京东抢购助手源代码Fork自https://github.com/tychxn/jd-assistant +-由于原作者已不再更新、刚好我又有需要、所以在此基础上进行了修改; ## 主要功能 From a81a8708f0e8a4ae2d1ae8d44261b936e738579c Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Thu, 22 Jul 2021 20:58:40 +0800 Subject: [PATCH 03/23] Update README.md --- README.md | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f67493e..dbaffea 100644 --- a/README.md +++ b/README.md @@ -55,31 +55,16 @@ pip install -r requirements.txt ## 更新记录 -- 【2020.03.10】修复了一些小问题。 -- 【2020.02.08】修复了查询库存接口响应数据结构变化导致的问题。 -- 【2020.02.06】添加下单成功消息推送功能;新增配置参数以减少各种异常情况。 -- 【2020.02.03】查询商品库存方法添加超时,避免少数情况下的卡死问题;对部分代码进行了优化。 -- 【2020.02.02】重写了监控库存提交订单功能:监控多商品时可以下单任一有库存商品,具体使用方式请参考wiki。 -- 【2020.01.29】修复了自定义商品数量时的bug。 -- 【2020.01.28】完善了监控库存提交订单功能的代码,具体使用方式请参考wiki。 -- 【2020.01.24】修复了查询单个商品库存接口需要添加额外参数的问题。 -- 【2020.01.15】提升了部分代码质量。 -- 【2019.12.14】解决查询单个商品库存接口变动的问题。 -- 【2019.11.10】临时增加预约商品抢购功能。 -- 【2019.02.16】更新了普通商品的抢购代码,在Wiki中写了一份使用教程。 -- 【2018.11.29】京东更新了抢购商品的下单接口,代码已更新,支持定时抢购。 -- 【2018.09.26】京东已下线`字符验证码`接口,`账号密码登录`功能失效,请使用扫码登录`asst.login_by_QRcode()`。 -- 【2018.07.28】京东已采用`滑动验证码`替换登录时出现的`字符验证码`,但还没有下线`字符验证码`接口,`账号密码登录`功能依旧可用。等待后续更新滑动验证方式,推荐使用`扫码登录`。 +- 【2021.07.22】在原作者代码基础上、增加了查询订单验证码功能 ## 备注 - 🌟强烈建议大家在部署代码前使用有货的商品测试下单流程,并且:在京东购物车结算页面设置发票为`电子普通发票-个人`,设置支付方式为`在线支付`,否则可能出现各种未知的下单失败问题。🌟 -- 京东商城的登陆/下单机制经常改动,当前测试时间`2020.02.08`。如果失效,欢迎提issue,我会来更新。 -- 代码在`macOS`中编写,如果在其他平台上运行出行问题,欢迎提issue。 +- 京东商城的登陆/下单机制经常改动,原jd-assistant最后一次更新时间时间`2020.03.08`。如果功能失效,欢迎提issue,有时间我会来更新。 +- 代码在`Win10`中编写,如果在其他平台上运行出行问题,欢迎提issue。 ## 待完成的功能 - -- [ ] Keep session alive +- [ ] 订单验证码查询 - [ ] 抢优惠券 ## 不考虑的功能 From 78b4e9a35eadedea70c79742fd30710276bbd633 Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Thu, 22 Jul 2021 20:59:21 +0800 Subject: [PATCH 04/23] Update README.md --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index dbaffea..3439f00 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,3 @@ pip install -r requirements.txt - ✖️ 支付功能 - ✖️ 多账号抢购 - -## Sponsor - -[![JetBrains](./docs/jetbrains.svg)](https://www.jetbrains.com/?from=jd-assistant) From 3dbe6fb39c3de96d80f25387284edca828d58c65 Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Thu, 22 Jul 2021 21:10:13 +0800 Subject: [PATCH 05/23] Update jd_assistant.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增查询已购订单的验证码 --- jd_assistant.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/jd_assistant.py b/jd_assistant.py index 8e69834..fefe6ae 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -1011,7 +1011,7 @@ def submit_order_by_time(self, buy_time, retry=4, interval=5): @check_login def get_order_info(self, unpaid=True): """查询订单信息 - :param unpaid: 只显示未付款订单,可选参数,默认为True + :param unpaid: 默认只显示未付款订单,可选参数,默认为True :return: """ url = 'https://order.jd.com/center/list.action' @@ -1086,6 +1086,41 @@ def get_order_info(self, unpaid=True): except Exception as e: logger.error(e) + @check_login + def get_order_vercode(self, orderId): + """ + 获取已购订单的验证码 + 先登录订单中心获取所有订单、通过订单查询验证码 + """ + #print(orderId) + url = "http://locdetails.jd.com/pc/locdetail?orderId={}&modelId=1".format(orderId) + payload = { + 'search': 0, + 'd': 1, + 's': 4096, + } # Orders for nearly three months + headers = { + 'User-Agent': self.user_agent, + 'Referer': 'https://passport.jd.com/uc/login?ltype=logout', + } + + try: + resp = self.sess.get(url=url, params=payload, headers=headers) + if not response_status(resp): + logger.error('获取订单页信息失败') + return + soup = BeautifulSoup(resp.text, "html.parser") + # logger.info('************************查询订单验证码************************') + + order_vercode_str = soup.select('td.tr-vercode.un-use') + #print(order_vercode_str) + pattern = (r'\d{12}') + order_vercode = re.findall(pattern, str(order_vercode_str))[0] + print("订单号:", orderId, " 验证码:",order_vercode) + + except Exception as e: + logger.error(e) + @deprecated def _get_seckill_url(self, sku_id): """获取商品的抢购链接 From 2972f1eefc996add2687fb4cfbad70bfa3888043 Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Fri, 23 Jul 2021 09:04:21 +0800 Subject: [PATCH 06/23] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3439f00..d95dbdc 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # JD-Assistant [![version](https://img.shields.io/badge/python-3.4+-blue.svg)](https://www.python.org/download/releases/3.4.0/) -[![status](https://img.shields.io/badge/status-stable-green.svg)](https://github.com/tychxn/jd-assistant) +[![status](https://img.shields.io/badge/status-stable-green.svg)](https://github.com/huaisha1224/jd-assistant) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) -[![star, issue](https://img.shields.io/badge/star%2C%20issue-welcome-brightgreen.svg)](https://github.com/tychxn/jd-assistant) +[![star, issue](https://img.shields.io/badge/star%2C%20issue-welcome-brightgreen.svg)](https://github.com/huaisha1224/jd-assistant) 京东抢购助手源代码Fork自https://github.com/tychxn/jd-assistant -由于原作者已不再更新、刚好我又有需要、所以在此基础上进行了修改; From 34dece841b89d275d49ed4cccd8e5bf33ef0dfa5 Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Fri, 23 Jul 2021 09:09:09 +0800 Subject: [PATCH 07/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d95dbdc..b11577b 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ pip install -r requirements.txt 程序主入口在 `main.py` -👉 [使用教程请参看Wiki](https://github.com/tychxn/jd-assistant/wiki/1.-%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B%E7%94%A8%E6%B3%95) +👉 [使用教程请参看Wiki](https://github.com/huaisha1224/jd-assistant/wiki/%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B) ## 更新记录 From aa49ae50fc1e5c393a7e3fdc779b2020cc659437 Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Fri, 23 Jul 2021 13:53:25 +0800 Subject: [PATCH 08/23] Update jd_assistant.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增验证码消费状态 --- jd_assistant.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/jd_assistant.py b/jd_assistant.py index fefe6ae..6c3c312 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -1032,7 +1032,7 @@ def get_order_info(self, unpaid=True): return soup = BeautifulSoup(resp.text, "html.parser") - logger.info('************************订单列表页查询************************') + # logger.info('************************订单列表页查询************************') order_table = soup.find('table', {'class': 'order-tb'}) table_bodies = order_table.select('tbody') exist_order = False @@ -1050,11 +1050,12 @@ def get_order_info(self, unpaid=True): exist_order = True - # get order_time, order_id + # 获取订单时间、订单ID tr_th = table_body.select('tr.tr-th')[0] order_time = get_tag_value(tr_th.select('span.dealtime')) order_id = get_tag_value(tr_th.select('span.number a')) - + #print(tr_th) + self.get_order_vercode(order_id) #调用查询验证码函数 # get sum_price, pay_method sum_price = '' pay_method = '' @@ -1077,9 +1078,9 @@ def get_order_info(self, unpaid=True): quantity = get_tag_value(tr_bd.select('div.goods-number'))[1:] items_dict[item_id] = quantity - order_info_format = '下单时间:{0}----订单号:{1}----商品列表:{2}----订单状态:{3}----总金额:{4}元----付款方式:{5}' - logger.info(order_info_format.format(order_time, order_id, parse_items_dict(items_dict), order_status, - sum_price, pay_method)) + # order_info_format = '下单时间:{0}----订单号:{1}----商品列表:{2}----订单状态:{3}----总金额:{4}元----付款方式:{5}' + # logger.info(order_info_format.format(order_time, order_id, parse_items_dict(items_dict), order_status, + # sum_price, pay_method)) if not exist_order: logger.info('订单查询为空') @@ -1113,10 +1114,18 @@ def get_order_vercode(self, orderId): # logger.info('************************查询订单验证码************************') order_vercode_str = soup.select('td.tr-vercode.un-use') + order_vercode_status = soup.select('td.un-use') + #print(order_vercode_status) #print(order_vercode_str) - pattern = (r'\d{12}') - order_vercode = re.findall(pattern, str(order_vercode_str))[0] - print("订单号:", orderId, " 验证码:",order_vercode) + #pattern = (r'\d{12}') + order_vercode = re.findall(r'\d{12}', str(order_vercode_str))[0] #订单验证码 + + if re.findall(r'未消费', str(order_vercode_status)): + order_status = re.findall(r'未消费', str(order_vercode_status))[0] #消费状态 + if order_status: + print("订单号:", orderId, " 验证码:",order_vercode, " 消费状态:", order_status) + else: + print("订单号:", orderId, " 验证码:",order_vercode) except Exception as e: logger.error(e) From f3cfdb306bf838bc5423805d85be67f8e92b116f Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Sun, 25 Jul 2021 22:47:10 +0800 Subject: [PATCH 09/23] new get_order_vercode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增get_order_vercode函数用来提取本地服务订单中的验证码信息 --- jd_assistant.py | 149 +++++++++++++++++++++++++++++++----------------- 1 file changed, 98 insertions(+), 51 deletions(-) diff --git a/jd_assistant.py b/jd_assistant.py index 6c3c312..e1bb16b 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -1032,14 +1032,13 @@ def get_order_info(self, unpaid=True): return soup = BeautifulSoup(resp.text, "html.parser") - # logger.info('************************订单列表页查询************************') + logger.info('************************订单列表页查询************************') order_table = soup.find('table', {'class': 'order-tb'}) table_bodies = order_table.select('tbody') exist_order = False for table_body in table_bodies: # get order status order_status = get_tag_value(table_body.select('span.order-status')).replace("订单状态:", "") - # check if order is waiting for payment # wait_payment = bool(table_body.select('a.btn-pay')) wait_payment = "等待付款" in order_status @@ -1050,12 +1049,9 @@ def get_order_info(self, unpaid=True): exist_order = True - # 获取订单时间、订单ID tr_th = table_body.select('tr.tr-th')[0] order_time = get_tag_value(tr_th.select('span.dealtime')) order_id = get_tag_value(tr_th.select('span.number a')) - #print(tr_th) - self.get_order_vercode(order_id) #调用查询验证码函数 # get sum_price, pay_method sum_price = '' pay_method = '' @@ -1078,58 +1074,15 @@ def get_order_info(self, unpaid=True): quantity = get_tag_value(tr_bd.select('div.goods-number'))[1:] items_dict[item_id] = quantity - # order_info_format = '下单时间:{0}----订单号:{1}----商品列表:{2}----订单状态:{3}----总金额:{4}元----付款方式:{5}' - # logger.info(order_info_format.format(order_time, order_id, parse_items_dict(items_dict), order_status, - # sum_price, pay_method)) + order_info_format = '下单时间:{0}----订单号:{1}----商品列表:{2}----订单状态:{3}----总金额:{4}元----付款方式:{5}' + logger.info(order_info_format.format(order_time, order_id, parse_items_dict(items_dict), order_status, + sum_price, pay_method)) if not exist_order: logger.info('订单查询为空') except Exception as e: logger.error(e) - @check_login - def get_order_vercode(self, orderId): - """ - 获取已购订单的验证码 - 先登录订单中心获取所有订单、通过订单查询验证码 - """ - #print(orderId) - url = "http://locdetails.jd.com/pc/locdetail?orderId={}&modelId=1".format(orderId) - payload = { - 'search': 0, - 'd': 1, - 's': 4096, - } # Orders for nearly three months - headers = { - 'User-Agent': self.user_agent, - 'Referer': 'https://passport.jd.com/uc/login?ltype=logout', - } - - try: - resp = self.sess.get(url=url, params=payload, headers=headers) - if not response_status(resp): - logger.error('获取订单页信息失败') - return - soup = BeautifulSoup(resp.text, "html.parser") - # logger.info('************************查询订单验证码************************') - - order_vercode_str = soup.select('td.tr-vercode.un-use') - order_vercode_status = soup.select('td.un-use') - #print(order_vercode_status) - #print(order_vercode_str) - #pattern = (r'\d{12}') - order_vercode = re.findall(r'\d{12}', str(order_vercode_str))[0] #订单验证码 - - if re.findall(r'未消费', str(order_vercode_status)): - order_status = re.findall(r'未消费', str(order_vercode_status))[0] #消费状态 - if order_status: - print("订单号:", orderId, " 验证码:",order_vercode, " 消费状态:", order_status) - else: - print("订单号:", orderId, " 验证码:",order_vercode) - - except Exception as e: - logger.error(e) - @deprecated def _get_seckill_url(self, sku_id): """获取商品的抢购链接 @@ -1457,3 +1410,97 @@ def buy_item_in_stock(self, sku_ids, area, wait_all=False, stock_interval=3, sub return time.sleep(stock_interval) + + @check_login + def get_order_vercode(self, unpaid_new=False): + """获取已购本地服务订单的验证码已经验证码状态 + 登录订单中心获取所有订单 + 通过本地服务订单接口查询是否为本地服务订单类型 + 查询验证码、并记录消费状态 + : + :vercode_url: 本地服务订单接口 + """ + url = 'https://order.jd.com/center/list.action' + payload = { + 'search': 0, + 'd': 1, + 's': 4096, + } # Orders for nearly three months + headers = { + 'User-Agent': self.user_agent, + 'Referer': 'https://passport.jd.com/uc/login?ltype=logout', + } + + try: + resp = self.sess.get(url=url, params=payload, headers=headers) + if not response_status(resp): + logger.error('获取订单页信息失败') + return + soup = BeautifulSoup(resp.text, "html.parser") + #print(soup) + + #logger.info('************************订单列表页查询************************') + order_table = soup.find('table', {'class': 'order-tb'}) + table_bodies = order_table.select('tbody') + exist_order = False + for table_body in table_bodies: + # get order status + order_status = get_tag_value(table_body.select('span.order-status')).replace("订单状态:", "") + wait_payment = "等待付款" in order_status + + # only show unpaid orders if unpaid=True + if unpaid_new and (not wait_payment): + continue + exist_order = True + + # 获取订单时间、订单ID + tr_th = table_body.select('tr.tr-th')[0] + order_time = get_tag_value(tr_th.select('span.dealtime')) + order_id = get_tag_value(tr_th.select('span.number a')) + #print("start") + # 本地服务订单接口查询查询消费验证码 + vercode_url = "http://locdetails.jd.com/pc/locdetail?orderId={}&modelId=1".format(order_id) + payload = { + 'search': 0, + 'd': 1, + 's': 4096, + } # Orders for nearly three months + headers = { + 'User-Agent': self.user_agent, + 'Referer': 'https://passport.jd.com/uc/login?ltype=logout', + } + + try: + resp = self.sess.get(url=vercode_url, params=payload, headers=headers) + if not response_status(resp): + logger.error('获取订单验证码页信息失败') + return + vercode_soup = BeautifulSoup(resp.text, "html.parser") + order_type = vercode_soup.select('h2') + + #通过本地服务订单接口查询订单时非本地服务器订单会提示"您的账号与订单信息不匹配或非loc订单,请重新跳转" + + if re.search(r'您的账号', str(order_type)): #判断订单是否为本地服务类型订单 + order_info_format = '下单时间: {0}---订单号: {1}----{2}' + logger.info(order_info_format.format(order_time, order_id, "非本地服务订单")) + else: #没有关键词说明是本地服务订单类型 + order_vercode_str = vercode_soup.select('td.tr-vercode.un-use') + order_vercode_status = vercode_soup.select('td.un-use') + order_vercode = re.findall(r'\d{12}', str(order_vercode_str))[0] #订单验证码 + + if re.findall(r'未消费', str(order_vercode_status)): + vercode_status = re.findall(r'未消费', str(order_vercode_status))[0] #消费状态 + if vercode_status: + order_info_format = '下单时间: {0}---订单号: {1}---验证码: {2} ---消费状态: {3}' + logger.info(order_info_format.format(order_time, order_id, order_vercode, vercode_status)) + else: + order_info_format = '下单时间: {0}---订单号: {1}---验证码: {2}----消费状态: {3}' + logger.info(order_info_format.format(order_time, order_id, order_vercode, "已消费")) + + except Exception as e: + logger.error(e) + + if not exist_order: + logger.info('订单查询为空') + except Exception as e: + logger.error(e) \ No newline at end of file From 95ada5e68a6b7b5bd17728cc4f4f71a0c6dc09ed Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Mon, 26 Jul 2021 13:04:44 +0800 Subject: [PATCH 10/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b11577b..17afc68 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ pip install -r requirements.txt - 代码在`Win10`中编写,如果在其他平台上运行出行问题,欢迎提issue。 ## 待完成的功能 -- [ ] 订单验证码查询 +- [✔] 订单验证码查询 - [ ] 抢优惠券 ## 不考虑的功能 From 39ed4bb2e64c4b36ad928d6ce73ac45c2083d375 Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Mon, 26 Jul 2021 14:01:58 +0800 Subject: [PATCH 11/23] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 17afc68..efeda1d 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ - 有货提交 - 定时提交 - 查询订单 (可选择只显示未付款订单) + - 查询本地生活服务订单中的验证码及其状态(验证码是否已消费) - 其他 - 商品预约 - 用户信息查询 From a6f1cde40a34f13ff3722ae4a1268c1024b5c33a Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Fri, 30 Jul 2021 13:41:57 +0800 Subject: [PATCH 12/23] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加异常错误处理、当获取订单失败时、打印错误信息及处理方案 --- jd_assistant.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/jd_assistant.py b/jd_assistant.py index e1bb16b..4f190f9 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -1034,6 +1034,10 @@ def get_order_info(self, unpaid=True): logger.info('************************订单列表页查询************************') order_table = soup.find('table', {'class': 'order-tb'}) + + # 判断一下订单获取是否成功 + if order_table == None: + logger.info('订单信息获取失败、请删除cookies文件夹后重新尝试') table_bodies = order_table.select('tbody') exist_order = False for table_body in table_bodies: @@ -1415,10 +1419,10 @@ def buy_item_in_stock(self, sku_ids, area, wait_all=False, stock_interval=3, sub def get_order_vercode(self, unpaid_new=False): """获取已购本地服务订单的验证码已经验证码状态 登录订单中心获取所有订单 - 通过本地服务订单接口查询是否为本地服务订单类型 + 通过本地生活服务订单接口查询是否为本地生活服务订单类型 查询验证码、并记录消费状态 : - :vercode_url: 本地服务订单接口 + :vercode_url: 本地生活服务订单接口 """ url = 'https://order.jd.com/center/list.action' payload = { @@ -1441,6 +1445,10 @@ def get_order_vercode(self, unpaid_new=False): #logger.info('************************订单列表页查询************************') order_table = soup.find('table', {'class': 'order-tb'}) + # 判断一下订单获取是否成功 + if order_table == None: + logger.info('订单信息获取失败、请删除cookies文件夹后重新尝试') + #print("订单信息获取失败、请删除cookies文件夹后重新尝试") table_bodies = order_table.select('tbody') exist_order = False for table_body in table_bodies: @@ -1482,7 +1490,7 @@ def get_order_vercode(self, unpaid_new=False): if re.search(r'您的账号', str(order_type)): #判断订单是否为本地服务类型订单 order_info_format = '下单时间: {0}---订单号: {1}----{2}' - logger.info(order_info_format.format(order_time, order_id, "非本地服务订单")) + logger.info(order_info_format.format(order_time, order_id, "非本地生活服务订单")) else: #没有关键词说明是本地服务订单类型 order_vercode_str = vercode_soup.select('td.tr-vercode.un-use') order_vercode_status = vercode_soup.select('td.un-use') @@ -1503,4 +1511,5 @@ def get_order_vercode(self, unpaid_new=False): if not exist_order: logger.info('订单查询为空') except Exception as e: + #print('报错啦') logger.error(e) \ No newline at end of file From 57c53185700ec4bceeaef82013840cdf9a9a93dc Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Tue, 3 Aug 2021 12:33:18 +0800 Subject: [PATCH 13/23] Update jd_assistant.py clean cookies --- jd_assistant.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/jd_assistant.py b/jd_assistant.py index 4f190f9..530bdfe 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -1085,7 +1085,9 @@ def get_order_info(self, unpaid=True): if not exist_order: logger.info('订单查询为空') except Exception as e: + self.clean_cookies() logger.error(e) + logger.info('已删除cookies、请重新运行程序') @deprecated def _get_seckill_url(self, sku_id): @@ -1512,4 +1514,15 @@ def get_order_vercode(self, unpaid_new=False): logger.info('订单查询为空') except Exception as e: #print('报错啦') - logger.error(e) \ No newline at end of file + self.clean_cookies() + logger.error(e) + logger.info('已删除cookies、请重新运行程序') + + def clean_cookies(self): + """清理cookies文件 + """ + cookies_path = os.getcwd() + '\cookies' + with os.scandir(cookies_path) as entries: + for entry in entries: + #print(entry.name) + os.remove(cookies_path + '\\' + entry.name) \ No newline at end of file From c03476e47f052f57b050f4155986dd235fb47d44 Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Tue, 3 Aug 2021 12:34:43 +0800 Subject: [PATCH 14/23] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index efeda1d..9e14c4b 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ pip install -r requirements.txt ## 更新记录 +- 【2021.08.03】优化代码、处理cookies失败情况下的异常情况 - 【2021.07.22】在原作者代码基础上、增加了查询订单验证码功能 ## 备注 From 0dbbec091ad577d5a40aa4605da3cc59c8249c59 Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Thu, 5 Aug 2021 23:08:29 +0800 Subject: [PATCH 15/23] Update jd_assistant.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化某些订单获取失败的问题 --- jd_assistant.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jd_assistant.py b/jd_assistant.py index 530bdfe..58fecab 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -1469,7 +1469,8 @@ def get_order_vercode(self, unpaid_new=False): order_id = get_tag_value(tr_th.select('span.number a')) #print("start") # 本地服务订单接口查询查询消费验证码 - vercode_url = "http://locdetails.jd.com/pc/locdetail?orderId={}&modelId=1".format(order_id) + vercode_url = "http://locdetails.jd.com/pc/locdetail?orderId={}&modelId=2".format(order_id) + #vercode_url_back = "http://locdetails.jd.com/pc/locdetail?orderId={}&modelId=1".format(order_id) payload = { 'search': 0, 'd': 1, From edbe55d9ddf4e7c76fabf35169e046cd651e3dc5 Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Thu, 5 Aug 2021 23:10:24 +0800 Subject: [PATCH 16/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e14c4b..4e358dc 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ pip install -r requirements.txt ## 更新记录 - +- 【2021.08.05】优化代码、处理某些特殊订单获取不到验证码的情况 - 【2021.08.03】优化代码、处理cookies失败情况下的异常情况 - 【2021.07.22】在原作者代码基础上、增加了查询订单验证码功能 From c4ffe795110a42c5b4db8f9166988ceacd0384d9 Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Fri, 6 Aug 2021 19:15:43 +0800 Subject: [PATCH 17/23] Update log.py --- log.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/log.py b/log.py index 61a789e..929e95a 100644 --- a/log.py +++ b/log.py @@ -2,8 +2,9 @@ # -*- encoding=utf8 -*- import logging import logging.handlers +from time import strftime -LOG_FILENAME = 'jd-assistant.log' +LOG_FILENAME = strftime("jd-assistant_%Y_%m_%d_%H_%M.log") logger = logging.getLogger() From a8cfa953eba11d4a2258901098c5a3ecb465d157 Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Thu, 12 Aug 2021 22:25:03 +0800 Subject: [PATCH 18/23] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E6=B6=88=E8=B4=B9=E6=97=B6=E9=97=B4=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加验证码消费时间输出 --- README.md | 1 + jd_assistant.py | 30 +++++++++++++++++++++++------- log.py | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4e358dc..da235a6 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ pip install -r requirements.txt ## 更新记录 +- 【2021.08.12】优化代码、输出增加验证码消费时间 - 【2021.08.05】优化代码、处理某些特殊订单获取不到验证码的情况 - 【2021.08.03】优化代码、处理cookies失败情况下的异常情况 - 【2021.07.22】在原作者代码基础上、增加了查询订单验证码功能 diff --git a/jd_assistant.py b/jd_assistant.py index 58fecab..491240e 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -1471,6 +1471,7 @@ def get_order_vercode(self, unpaid_new=False): # 本地服务订单接口查询查询消费验证码 vercode_url = "http://locdetails.jd.com/pc/locdetail?orderId={}&modelId=2".format(order_id) #vercode_url_back = "http://locdetails.jd.com/pc/locdetail?orderId={}&modelId=1".format(order_id) + #vercode_url= "https://locdetails.jd.com/pc/locdetail?orderId=217734548778&modelId=2" payload = { 'search': 0, 'd': 1, @@ -1487,26 +1488,41 @@ def get_order_vercode(self, unpaid_new=False): logger.error('获取订单验证码页信息失败') return vercode_soup = BeautifulSoup(resp.text, "html.parser") - order_type = vercode_soup.select('h2') + + #获取完整订单信息 + # for row in vercode_soup.select('tbody tr'): + # row_text = [x.text for x in row.find_all('td')] + # #vercode_tr = (', '.join(row_text)) + # vercode_tr = (', '.join(row_text).replace('\n','').replace(' ', '').replace('\r\n', '')) + # print(vercode_tr.split(',',1)[0]) + # print(vercode_tr.split(',',2)[1]) + + order_type = vercode_soup.select('h2') #判断异常 #通过本地服务订单接口查询订单时非本地服务器订单会提示"您的账号与订单信息不匹配或非loc订单,请重新跳转" if re.search(r'您的账号', str(order_type)): #判断订单是否为本地服务类型订单 order_info_format = '下单时间: {0}---订单号: {1}----{2}' logger.info(order_info_format.format(order_time, order_id, "非本地生活服务订单")) - else: #没有关键词说明是本地服务订单类型 - order_vercode_str = vercode_soup.select('td.tr-vercode.un-use') - order_vercode_status = vercode_soup.select('td.un-use') + + #没有关键词说明是本地服务订单类型 + else: + order_vercode_str = vercode_soup.select('td.tr-vercode.un-use') #定位验证码位置 + order_vercode_status = vercode_soup.select('td.un-use') #消费状态 + order_vercode = re.findall(r'\d{12}', str(order_vercode_str))[0] #订单验证码 - if re.findall(r'未消费', str(order_vercode_status)): - vercode_status = re.findall(r'未消费', str(order_vercode_status))[0] #消费状态 + if re.findall(r'未消费', str(order_vercode_status)): #判断消费状态 + vercode_status = re.findall(r'未消费', str(order_vercode_status))[0] if vercode_status: order_info_format = '下单时间: {0}---订单号: {1}---验证码: {2} ---消费状态: {3}' logger.info(order_info_format.format(order_time, order_id, order_vercode, vercode_status)) + else: + # 获取验证码消费时间 + vercode_usetime = re.findall(r"(\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2} 已消费)", str(vercode_soup)) order_info_format = '下单时间: {0}---订单号: {1}---验证码: {2}----消费状态: {3}' - logger.info(order_info_format.format(order_time, order_id, order_vercode, "已消费")) + logger.info(order_info_format.format(order_time, order_id, order_vercode, vercode_usetime)) except Exception as e: logger.error(e) diff --git a/log.py b/log.py index 929e95a..e4626c8 100644 --- a/log.py +++ b/log.py @@ -4,7 +4,7 @@ import logging.handlers from time import strftime -LOG_FILENAME = strftime("jd-assistant_%Y_%m_%d_%H_%M.log") +LOG_FILENAME = strftime("jd-assistant_%Y_%m_%d_%H.log") logger = logging.getLogger() From 28fc50f584d470940bf7970c93c3c466a8332acc Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Sat, 14 Aug 2021 12:39:37 +0800 Subject: [PATCH 19/23] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 代码优化 --- jd_assistant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jd_assistant.py b/jd_assistant.py index 491240e..67de02e 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -1516,7 +1516,7 @@ def get_order_vercode(self, unpaid_new=False): vercode_status = re.findall(r'未消费', str(order_vercode_status))[0] if vercode_status: order_info_format = '下单时间: {0}---订单号: {1}---验证码: {2} ---消费状态: {3}' - logger.info(order_info_format.format(order_time, order_id, order_vercode, vercode_status)) + logger.info(order_info_format.format(order_time, order_id, order_vercode, vercode_status[0])) else: # 获取验证码消费时间 From 1ed89c68623adf9b0a07b55888d0c1ce912a10ed Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Sun, 22 Aug 2021 21:16:23 +0800 Subject: [PATCH 20/23] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=B0=E7=9F=B3=E5=A2=A8=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持提交数据到石墨文档 --- jd_assistant.py | 1 + shimo.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 shimo.py diff --git a/jd_assistant.py b/jd_assistant.py index 67de02e..9029bfb 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -10,6 +10,7 @@ import requests from bs4 import BeautifulSoup +import shimo from config import global_config from exception import AsstException from log import logger diff --git a/shimo.py b/shimo.py new file mode 100644 index 0000000..d202255 --- /dev/null +++ b/shimo.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# -*- coding:utf-8 -*- +""" + 提交数据到石墨文档 +""" +from util import response_status +import requests + +def shimo(content): + """提交数据到石墨文档表单收集器 + """ + # 石墨文档提交数据格式 + data = { + "duration" : 55, + "formRev" : 1, + "responseContent" : [ + { + "guid" : "xxxxx", #石墨文档的guid + "text" : { + "content" : "xxxxxxxx" + }, + "type" : 0 + } + ], + "userFinger" : "-1", + "userName" : "JD" + } + + url = "https://shimo.im/api/newforms/forms/xpVxJQJjT3GJ8WhJ/submit" + + data['duration'] = 50 + data['responseContent'][0]['text']['content'] = content + data['userName'] = "JD助手" + # print("Duration: ", data['duration']) + # print("userName: ",data['userName']) + # print("Content: ", data['responseContent'][0]['text']['content']) + # print(data) + + response = requests.post(url, json=data) #用post方式提交数据 + if response.status_code == 200 or 204: + #print(response.status_code) + return True + else: + return False + +if __name__ == '__main__': + vercode = ['7102298241802','1369696304672','5557372871652'] + for x in vercode: + shimo(x) + # ok = shimo(x) + # print(ok) \ No newline at end of file From 8b73b9af5a683ba4634bf4433a3ff35d27b28297 Mon Sep 17 00:00:00 2001 From: "Sam.Huang" Date: Mon, 23 Aug 2021 23:25:45 +0800 Subject: [PATCH 21/23] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index da235a6..9b8f23b 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ pip install -r requirements.txt ## 更新记录 +- 【2021.08.23】增加shimo.py模块、支持提交数据到石墨文档 - 【2021.08.12】优化代码、输出增加验证码消费时间 - 【2021.08.05】优化代码、处理某些特殊订单获取不到验证码的情况 - 【2021.08.03】优化代码、处理cookies失败情况下的异常情况 From 40778b540528198eb06e0f5c7db14dc5f203b165 Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Tue, 24 Aug 2021 23:16:33 +0800 Subject: [PATCH 22/23] Update shimo.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit shimo模块代码优化 --- shimo.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shimo.py b/shimo.py index d202255..fcf49a7 100644 --- a/shimo.py +++ b/shimo.py @@ -3,15 +3,16 @@ """ 提交数据到石墨文档 """ -from util import response_status + import requests +import random def shimo(content): """提交数据到石墨文档表单收集器 """ # 石墨文档提交数据格式 data = { - "duration" : 55, + "duration" : 55, #时间 "formRev" : 1, "responseContent" : [ { @@ -28,7 +29,7 @@ def shimo(content): url = "https://shimo.im/api/newforms/forms/xpVxJQJjT3GJ8WhJ/submit" - data['duration'] = 50 + data['duration'] = random.randint(10,50) #生成随机时间 data['responseContent'][0]['text']['content'] = content data['userName'] = "JD助手" # print("Duration: ", data['duration']) From 0cb8f8d771ce258478574a1b7f12138e9e78faf9 Mon Sep 17 00:00:00 2001 From: huaisha1224 Date: Mon, 6 Sep 2021 13:09:45 +0800 Subject: [PATCH 23/23] 1 --- README.md | 1 + jd_assistant.py | 21 ++++++++------------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 9b8f23b..ba72076 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ pip install -r requirements.txt ## 更新记录 +- 【2021.09.06】代码优化 - 【2021.08.23】增加shimo.py模块、支持提交数据到石墨文档 - 【2021.08.12】优化代码、输出增加验证码消费时间 - 【2021.08.05】优化代码、处理某些特殊订单获取不到验证码的情况 diff --git a/jd_assistant.py b/jd_assistant.py index 9029bfb..a6fcfaf 100644 --- a/jd_assistant.py +++ b/jd_assistant.py @@ -10,12 +10,12 @@ import requests from bs4 import BeautifulSoup -import shimo from config import global_config from exception import AsstException from log import logger from messenger import Messenger from timer import Timer +import shimo from util import ( DEFAULT_TIMEOUT, DEFAULT_USER_AGENT, @@ -1490,14 +1490,6 @@ def get_order_vercode(self, unpaid_new=False): return vercode_soup = BeautifulSoup(resp.text, "html.parser") - #获取完整订单信息 - # for row in vercode_soup.select('tbody tr'): - # row_text = [x.text for x in row.find_all('td')] - # #vercode_tr = (', '.join(row_text)) - # vercode_tr = (', '.join(row_text).replace('\n','').replace(' ', '').replace('\r\n', '')) - # print(vercode_tr.split(',',1)[0]) - # print(vercode_tr.split(',',2)[1]) - order_type = vercode_soup.select('h2') #判断异常 #通过本地服务订单接口查询订单时非本地服务器订单会提示"您的账号与订单信息不匹配或非loc订单,请重新跳转" @@ -1516,14 +1508,16 @@ def get_order_vercode(self, unpaid_new=False): if re.findall(r'未消费', str(order_vercode_status)): #判断消费状态 vercode_status = re.findall(r'未消费', str(order_vercode_status))[0] if vercode_status: - order_info_format = '下单时间: {0}---订单号: {1}---验证码: {2} ---消费状态: {3}' - logger.info(order_info_format.format(order_time, order_id, order_vercode, vercode_status[0])) + submit = shimo.shimo(order_vercode) #调用石墨文档模块提交数据 + #print(order_vercode) + order_info_format = '下单时间: {0}---订单号: {1}---验证码: {2} ---消费状态: {3}---提交状态: {4}' + logger.info(order_info_format.format(order_time, order_id, order_vercode, vercode_status, submit)) else: # 获取验证码消费时间 vercode_usetime = re.findall(r"(\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2} 已消费)", str(vercode_soup)) order_info_format = '下单时间: {0}---订单号: {1}---验证码: {2}----消费状态: {3}' - logger.info(order_info_format.format(order_time, order_id, order_vercode, vercode_usetime)) + logger.info(order_info_format.format(order_time, order_id, order_vercode, vercode_usetime[0])) except Exception as e: logger.error(e) @@ -1543,4 +1537,5 @@ def clean_cookies(self): with os.scandir(cookies_path) as entries: for entry in entries: #print(entry.name) - os.remove(cookies_path + '\\' + entry.name) \ No newline at end of file + os.remove(cookies_path + '\\' + entry.name) + os.system('pause') \ No newline at end of file