Coder Social home page Coder Social logo

tychxn / jd-assistant Goto Github PK

View Code? Open in Web Editor NEW
5.1K 109.0 1.9K 6.83 MB

京东抢购助手:包含登录,查询商品库存/价格,添加/清空购物车,抢购商品(下单),查询订单等功能

License: MIT License

Python 98.74% HTML 0.88% JavaScript 0.38%
jingdong buy python3 assistant jd

jd-assistant's Issues

venderId以及返回json格式改变

payload里venderId现在变得需要了,如果不提供这个参数,json会返回

{
	"StockState": 33,
	"area": {
		"townName": "",
		"provinceName": "北京",
		"cityName": "朝阳区",
		"success": true,
		"countyName": "三环以内"
	},
	"realSkuId": 100006176160,
	"choseSuit": [],
	"code": 1,
	"err": true,
	"PopType": 0,
	"ArrivalDate": null,
	"IsPurchase": false,
	"StockStateName": "有货",
	"rn": -1
}

然后会一直提交失败。
然后正常返回的json格式变了,当然也不一定是所有的都这样吧,我这里是看的id为100006176160的商品,这会导致的结果就是jd_assistant.py第437行找不到关键字StockState

{
	"stock": {
		"freshEdi": null,
		……
		"area": {
			"townName": "",
			"cityName": "朝阳区",
			"success": true,
			"provinceName": "北京",
			"countyName": "三环以内"
		},
		……
		"StockState": 34,
		"StockStateName": "无货",
		……
		"ArrivalDate": "",
		"v": "0"
	},
	"choseSuit": []
}

目前我在419行的payload里添加了商品venderId(好像就是店铺首页url的那串数字),然后在stock_state之前添加了resp_json = resp_json['stock']

京东支付接口

能不能做一个对指定订单的支付接口呀,使用京东支付就可以

能否增加取消订单功能

碰到个问题:在下一批订单(提交订单未付款)的时候,有很多订单并不需要,最好能取消这些未付款的订单,根据订单号取消即可

config.ini 需要configparser 模块读取

from config import global_config
jd_assistant.py中该行错误,python3环境需要添加configparse模块:
import configparser

global_config = configparser.ConfigParser()
#global_config.readfp(open('config.ini'))
global_config.read('config.ini',encoding='utf-8')

第二个问题是,弹出来的二维码不能用京东app扫描登录,Android APP 最新版。

怎么使用的问题,

大佬你好,我是一个小白,对于怎么使用应该说明一下。 谢谢啦。 大佬辛苦

submit_order_by_stock问题

def submit_order_by_stock(self, sku_id='251837', area='12_904_3375', interval=3):
while True:
if self.if_item_in_stock(sku_id=sku_id, area=area):
print(get_current_time(), '%s有货了,正在提交订单……' % sku_id)
self.add_item_to_cart(sku_id) ##少了这个好像不能提交订单呀
self.submit_order()
break
else:
print(get_current_time(), '%s无货,准备下一次查询……' % sku_id)
time.sleep(interval)

有货下单修改区域id提示错误

raceback (most recent call last):
File "main.py", line 13, in
asst.submit_order_by_stock(sku_ids=sku_ids, area=area, interval=5) # 监控的商品id和地址id,库存满足时提交订单
File "c:\jd\jd_assistant.py", line 874, in submit_order_by_stock
if self.if_item_can_be_ordered(sku_ids=sku_ids, area=area):
File "c:\jd\jd_assistant.py", line 544, in if_item_can_be_ordered
else self.get_single_item_stock(sku_id=sku_ids[0], area=area)
File "c:\jd\jd_assistant.py", line 443, in get_single_item_stock
stock_state = resp_json['stock']['StockState'] # 33 -- 现货 0,34 -- 无货 36 -- '采购中' 40 -- 可配货
KeyError: 'stock'

只能使用1_72_4211,使用其他的区域id报错

提交订单完成后,未能查询订单信息。

提交订单完成后,未能查询订单信息。

[2018-12-06 09:19:11] 登录成功
[2018-12-06 09:19:12] 购物车清空成功
[2018-12-06 09:19:13] 4876809已成功加入购物车
[2018-12-06 09:19:16] 4876809有货了,正在提交订单……
[2018-12-06 09:19:16] 订单提交成功! 订单号:82835XXXXXX
订单列表页查询
[2018-12-06 09:19:16] 'NoneType' object has no attribute 'select'

如果单独查询订单,不提交订单,则是可以成功:

[2018-12-06 09:21:05] 登录成功
[2018-12-06 09:21:06] 购物车清空成功
[2018-12-06 09:21:07] 4876809已成功加入购物车
订单列表页查询
订单号:8283XXXXXX----下单时间:2018-12-06 09:20:37----商品列表:4876809 x 1----订单状态:等待付款----总金额:1699.00元----付款方式:在线支付

查库存一直403了

按照抓包的url 参数格式应该一致
payload = {
'skuId':sku_id,
'area':area,
'venderId':'1000004319',
'cat':'670,12800,12801',
'buyNum':1,
'choseSuitSkuIds':'',
'extraParam':'{"originid":"1"}',
'ch':1,
'fqsp':0,
'pduid':'15349258357301594241878',
'pdpin':'2834340621',
# 'detailedAdd':'null',
'callback':'jQuery{}'.format(random.randint(1000000, 9999999)),

读取配置文件时候,会出现\ufeff。修改成 encoding='UTF-8-sig' 就正常运行了

File "D:\pyworkspace\jd-assistant\config.py", line 19, in
global_config = Config()
File "D:\pyworkspace\jd-assistant\config.py", line 13, in init
self._config.read(self.path, encoding='utf-8')
File "D:\Python27\lib\site-packages\backports\configparser_init
.py", line 697, in read
self.read(fp, filename)
File "D:\Python27\lib\site-packages\backports\configparser_init
.py", line 1093, in _read
raise MissingSectionHeaderError(fpname, lineno, line)
backports.configparser.MissingSectionHeaderError: File contains no section headers.
file: 'D:\pyworkspace\jd-assistant\config.ini', line: 1
u'\ufeff[account]\n'

GBK编码问题。如何解决。百度了下 没啥思路。

Traceback (most recent call last):
File "main.py", line 3, in
from jd_assistant import Assistant
File "F:\jdqg\jd_assistant.py", line 12, in
from config import global_config
File "F:\jdqg\config.py", line 19, in
global_config = Config()
File "F:\jdqg\config.py", line 13, in init
self._config.read(self._path)
File "D:\Python\Python37\lib\configparser.py", line 696, in read
self._read(fp, filename)
File "D:\Python\Python37\lib\configparser.py", line 1014, in _read
for lineno, line in enumerate(fp, start=1):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 14: illegal m
ultibyte sequence

无法使用

在安装requirements中的环境时便有错误提示 按教程修改了main.py后双击后一闪而过 因为本人没有学习python 所以恳请能有更详细一点的教学 或tg群QQ之类的也可以 万分感激

定时下单过程中可能需要添加购物车动作

在定时下单 或者有货下单流程中 如果本身商品处于无货状态是不能添加到购物车的,拿着时候在 轮训货物状态或者时间的时候时不时应该 在有活或者到时间时候在考虑添加购物车动作呢?

无法登陆

[2018-11-04 12:32:44] 本次登录需要验证码
验证码:UYNK
[2018-11-04 12:32:52] 请刷新页面后重新提交
Traceback (most recent call last):
File "main.py", line 9, in
print(asst.get_item_stock_state(sku_id='35025101345', area='12_984_3383'))
File "C:\Users\hjh\Downloads\jd-assistant-master\jd_assistant.py", line 328, in get_item_stock_state
page = self._get_item_detail_page(sku_id)
File "C:\Users\hjh\Downloads\jd-assistant-master\jd_assistant.py", line 322, in _get_item_detail_page
page = self.sess.get(url=url, headers=self.headers)
File "D:\Anaconda3\lib\site-packages\requests\sessions.py", line 525, in get
return self.request('GET', url, **kwargs)
File "D:\Anaconda3\lib\site-packages\requests\sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "D:\Anaconda3\lib\site-packages\requests\sessions.py", line 644, in send
history = [resp for resp in gen] if allow_redirects else []
File "D:\Anaconda3\lib\site-packages\requests\sessions.py", line 644, in
history = [resp for resp in gen] if allow_redirects else []
File "D:\Anaconda3\lib\site-packages\requests\sessions.py", line 140, in resolve_redirects
raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects, response=resp)
requests.exceptions.TooManyRedirects: Exceeded 30 redirects.

刚刚试了一下,已经失效了

没抢到,测试了一下一个不缺货的抢购商品。

[2019-11-01 00:07:44] 时间到达,开始执行……
[2019-11-01 00:07:44] 开始抢购商品:33372426474
[2019-11-01 00:07:44] 第[1/10]次尝试抢购商品:33372426474
[2019-11-01 00:07:44] 抢购链接获取失败,33372426474不是抢购商品或抢购页面暂未刷新,1秒后重试

360截图20191101001009068

订单提交失败

订单提交失败, 返回信息如下:
[2019-02-10 17:09:39] {'orderXml': None, 'cartXml': None, 'noStockSkuIds': '', 'reqInfo': None, 'hasJxj': False, 'addedServiceList': None, 'overSea': False, 'sign': None, 'pin': '1017052447_m', 'needCheckCode': False, 'success': False, 'resultCode': 60074, 'orderId': 0, 'submitSkuNum': 0, 'deductMoneyFlag': 0, 'goJumpOrderCenter': False, 'payInfo': None, 'scaleSkuInfoListVO': None, 'purchaseSkuInfoListVO': None, 'noSupportHomeServiceSkuList': None, 'msgMobile': None, 'addressVO': None, 'msgUuid': None, 'message': '优惠券不满足使用条件'}

登录

是不是验证码登录已经废弃?新的登录方式什么时候上代码?

使用有货时提交订单,开始运行程序会直接提示有货了直接下单

【1715496】有货了,正在提交订单……
[2020-01-24 13:55:51] 订单提交失败, 错误码:600158, 返回信息:霍尼韦尔(Honeywell)口罩 KN95 防尘H930V 25只/盒 自吸式防 细小颗粒物 男女骑行口罩商品无货
[2020-01-24 13:55:51] {'message': '霍尼韦尔(Honeywell)口罩 KN95 防尘H930V 25只/盒 自吸式防细小颗粒物 男女骑行口罩商品 无货', 'deductMoneyFlag': 0, 'orderId': 0, 'msgMobile': None, 'success': False, 'scaleSkuInfoListVO': None, 'noStockSkuIds': '1715496', 'cartXml': None, 'pin': 'jd_WwKLRLvEUCIh', 'hasJxj': False, 'sign': None, 'purchaseSkuInfoListVO': None, 'noSupportHomeServiceSkuList': None, 'orderXml': None, 'msgUuid': None, 'reqInfo': None, 'resultCode': 600158, 'overSea': False, 'addressVO': {'id': 0, 'siteType': 0, 'used': False, 'provinceName': None, 'newProvinceId': 0, 'canSelected': False, 'freePay': False, 'appId': None, 'siteCityId': 0, 'mapping': False, 'appSelfPickAddress': 0, 'helpMessage': None, 'fullAddress': '地址', 'newCityName': None, 'siteTownId': 0, 'checkLevel': 0, 'coord_type': 0, 'specialRemark': None, 'associateAddressId': 0, 'pickVOname': None, 'newCountyId': 0, 'dataSign': 0, 'skuSupported': False, 'showChangeJingAddressFlag': None, 'selfPickOptimize': 0, 'addressType': 0, 'limitKeyword': 0, 'townId': 53120, 'areaName': '', 'associatePickId': 0, 'updateTime': None, 'isCod': 0, 'oldAddress': False, 'countyId': 43272, 'address': None, 'pickName': None, 'areaCode': None, 'mapUrl': None, 'consigneeName': None, 'newCountyName': None, 'townName': None, 'newTownId': 0, 'selected': False, 'longitude': 0.0, 'pickVOselected': False, 'cabinetAvailable': True, 'mobile': '18888888888', 'phone': None, 'tipInfo': None, 'pin': 'jd_WwKLRLvEUCIh', 'postCode': None, 'selfPickAddressShuntFlag': 0, 'idCard': '', 'selfPickMobile': None, 'lastOrderAddress': False, 'email': None, 'siteCountyId': 0, 'newCityId': 0, 'pickType': 0, 'giftSenderConsigneeName': None, 'newProvinceName': None, 'cityName': None, 'selectedAddressType': 0, 'message': None, 'addressMapperInfoVO': None, 'siteProvinceId': 0, 'cityId': 1387, 'addressDefaultCancel': None, 'latitude': 0.0, 'sendMq': 0, 'addressName': None, 'encryptText': None, 'certNum': None, 'gcLng': 0.0, 'optimizePickID': 0, 'giftSenderConsigneeMobile': None, 'userDefinedTag': None, 'consigneeId': 0, 'retTag': 0, 'addressDefault': False, 'selfPickPhone': None, 'tagSource': 0, 'countyName': None, 'paymentId': 0, 'addressDetail': '地址', 'provinceId': 17, 'branchId': 0, 'newTownName': None, 'pickId': 0, 'name': '小白', 'overseas': 0, 'shipmentType': 0, 'gcLat': 0.0, 'nameCode': None, 'addressSupported': 0}, 'goJumpOrderCenter': False, 'addedServiceList': None, 'submitSkuNum': 0, 'payInfo': None, 'needCheckCode': False}

使用检测是否有货的代码购买商品,失败

C:\Users\1\jd-assistant-master>python main.py
[2019-05-10 11:59:45] 登录成功
[2019-05-10 11:59:46] 购物车清空成功
[2019-05-10 11:59:46] 1958267078 x 1 已成功加入购物车
[2019-05-10 11:59:47] 【1958267078】有货了,正在提交订单……
[2019-05-10 11:59:47] 订单提交失败, 错误码:60077, 返回信息:获取用户订单信息失败(可能是购物车为空 或 未勾选购物车中商品)
[2019-05-10 11:59:47] {'overSea': False, 'orderXml': None, 'cartXml': None, 'noStockSkuIds': '', 'reqInfo': None, 'hasJxj': False, 'addedServiceList': None, 'sign': None, 'pin': 'jd_731f078b31483', 'needCheckCode': False, 'success': False, 'resultCode': 60077, 'orderId': 0, 'submitSkuNum': 0, 'deductMoneyFlag': 0, 'goJumpOrderCenter': False, 'payInfo': None, 'scaleSkuInfoListVO': None, 'purchaseSkuInfoListVO': None, 'noSupportHomeServiceSkuList': None, 'msgMobile': None, 'addressVO': None, 'msgUuid': None, 'message': '获取用户订单信息失败'}
[2019-05-10 11:59:47] 【1958267078】有货了,正在提交订单……
[2019-05-10 11:59:47] 订单提交失败, 错误码:60017, 返回信息:您多次提交过快,请稍后再试
[2019-05-10 11:59:47] {'overSea': False, 'orderXml': None, 'cartXml': None, 'noStockSkuIds': '', 'reqInfo': None, 'hasJxj': False, 'addedServiceList': None, 'sign': None, 'pin': 'jd_731f078b31483', 'needCheckCode': False, 'success': False, 'resultCode': 60017, 'orderId': 0, 'submitSkuNum': 0, 'deductMoneyFlag': 0, 'goJumpOrderCenter': False, 'payInfo': None, 'scaleSkuInfoListVO': None, 'purchaseSkuInfoListVO': None, 'noSupportHomeServiceSkuList': None, 'msgMobile': None, 'addressVO': None, 'msgUuid': None, 'message': '您多次提交过快,请稍后再试'}
[2019-05-10 11:59:48] 【1958267078】有货了,正在提交订单……
[2019-05-10 11:59:48] 订单提交失败, 错误码:60017, 返回信息:您多次提交过快,请稍后再试
[2019-05-10 11:59:48] {'reqInfo': None, 'hasJxj': False, 'addedServiceList': None, 'overSea': False, 'orderXml': None, 'cartXml': None, 'noStockSkuIds': '', 'sign': None, 'pin': 'jd_731f078b31483', 'needCheckCode': False, 'success': False, 'resultCode': 60017, 'orderId': 0, 'submitSkuNum': 0, 'deductMoneyFlag': 0, 'goJumpOrderCenter': False, 'payInfo': None, 'scaleSkuInfoListVO': None, 'purchaseSkuInfoListVO': None, 'noSupportHomeServiceSkuList': None, 'msgMobile': None, 'addressVO': None, 'msgUuid': None, 'message': '您多次提交过快,请稍后再试'}

Wiki 中有一处笔误

3.1.3 有货提交订单示例
示例代码中
asst.submit_order_by_stock(sku_id='100001324422', area='1_2802_2821') # 监控的商品id和地址id
sku_id应该是sku_ids

望修复,谢谢

请问预约商品现在是否可以抢购

我这里预约商品出现json错误
File "D:\python\Python3\lib\json_init_.py", line 319, in loads
return _default_decoder.decode(s)
File "D:\python\Python3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\python\Python3\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

问题出在这个代码
asst.exec_seckill(sku_id='100000822965', retry=30, interval=1)

提示:'NoneType' object has no attribute 'select'

你好:
在使用这个程序时,对应的商品没有成功加入到购物车。请问是什么原因造成的?谢谢

[2018-09-22 19:53:47] 本次登录不需要验证码
[2018-09-22 19:53:47] 请刷新页面后重新提交
(33, '现货')
4899.00
[2018-09-22 19:53:48] 购物车清空成功
[2018-09-22 19:53:48] 3517674已成功加入购物车
购物车商品详情
商品名称:JBL CINEMA 625 音响 音箱 5.1 家庭影院 电视音响 落地影院 组合音响 客厅影院 音响套装 HIFI----单价:¥4899.00----数量:1----总价:¥4899.00
[2018-09-22 19:53:49] list index out of range

订单列表页查询
[2018-09-22 19:53:49] 'NoneType' object has no attribute 'select'

Process finished with exit code 0

下单的时候提示获取用户信息失败。

<class 'dict'>: {'overSea': False, 'orderXml': None, 'cartXml': None, 'noStockSkuIds': '', 'reqInfo': None, 'hasJxj': False, 'addedServiceList': None, 'sign': None, 'pin': 'jd_5dxxxxxc75e59', 'needCheckCode': False, 'success': False, 'resultCode': 60002, 'orderId': 0, 'submitSkuNum': 0, 'deductMoneyFlag': 0, 'goJumpOrderCenter': False, 'payInfo': None, 'scaleSkuInfoListVO': None, 'purchaseSkuInfoListVO': None, 'noSupportHomeServiceSkuList': None, 'msgMobile': None, 'addressVO': None, 'msgUuid': None, 'message': '下单获取用户信息失败'}

正常运行,有几个问题恳请解答一下

无意中看到作者作品,感谢开源。代码写得很详细,赞一个。虽然我不懂PY。
1.请问eid和fp两个参数是什么意思?两个参数都用默认的有什么影响吗?默认的有效期是多久呢?
2.能否实现一下eid和fp的获得进行代码实现呢?
优化建议:
1.我测试了一个下架商品。使用的是查库存下单模式,发现在下架商品中是无法加入购物车的,所以 后面 查询到库存以后再下单我怀疑会失败。
2.在测试阶段发现 当查库存接口返回了 有货,但是仍然下单失败,经过初步排查我认为是因为店家在后台补充了库存,但是没有把商品上架,所以会一直下单失败。建议 针对已经下架的商品除了监测后台是否有库存,还要监测商品是否正常上架了。
以上的两个问题都是基于已经下架的商品做的测试,可能情况有些特殊,还请作者持续完善。
如描述不清楚的地方请和我联系企鹅:1127653664

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.