item_search_coupon - 京东优惠券查询

385 篇文章 2 订阅
95 篇文章 2 订阅

为了进行电商平台API开发,我们需要做下面几件事情。

1)开发者注册一个账号

2)然后在平台应用注册一个应用程序键(App Key) 。

3)下载平台API的SDK并掌握基本的API基础知识和调用

4)利用SDK接口和对象,传入AppKey或者必要的时候获取并传入SessionKey来进行程序开发。

5)利用平台提供的API文档中心和测试工具,对接口进行测试。从而了解返回信息,方便程序获取。
以上是电商平台的API应用开发的关键流程,其中通过平台文档中心和API测试工具,进行概念了解和接口信息查询很重要。因为这些数据就是我们需要在逐步显示出来的。lazada 的API很多,不过都分为了好几个领域,慢慢就会了解深入了。
在这里插入图片描述
点击获取key和secret
API 返回结果

Request address:
https://api-gw.onebound.cn/jd/item_search_coupon/?key=test_api_key&
&num_iid=10335871600&&lang=zh-CN&secret=
---------------------------------------
Result Object:
---------------------------------------
{
	"items": {
		"num_iid": "10335871600",
		"data_from": "app",
		"item": [
			{
				"addDays": 0,
				"anotherType": 0,
				"applicability": true,
				"area": 1,
				"batchId": 916119289,
				"beginTime": "2022.08.16",
				"couponId": "916119289",
				"couponKind": 2,
				"couponStyle": 0,
				"couponType": 1,
				"discount": 50,
				"discountText": "以下商品可使用满459减50的优惠券",
				"encryptedKey": "g9u6iadde42f0b20422dfc7ba39017cc",
				"endTime": "2022.08.19",
				"labelTxt": "店铺东券",
				"limitType": 5,
				"milliSecond": 0,
				"multipleDiscount": false,
				"name": "仅可购买安踏悠购专卖店商品",
				"overlap": false,
				"personalCoupon": false,
				"platform": 0,
				"plusCoupon": false,
				"quota": 459,
				"roleId": 83799669,
				"timeDesc": "有效期2022-08-16至2022-08-19",
				"toUrl": "mall.jd.com/index-213251.html",
				"userRiskLevel": 5
			},
			{
				"addDays": 0,
				"anotherType": 0,
				"applicability": true,
				"area": 1,
				"batchId": 915553761,
				"beginTime": "2022.08.16",
				"couponId": "915553761",
				"couponKind": 2,
				"couponStyle": 0,
				"couponType": 1,
				"discount": 30,
				"discountText": "以下商品可使用满359减30的优惠券",
				"encryptedKey": "g7ucibd5e82e04264e6733c875adde9f",
				"endTime": "2022.08.19",
				"labelTxt": "店铺东券",
				"limitType": 5,
				"milliSecond": 0,
				"multipleDiscount": false,
				"name": "仅可购买安踏悠购专卖店商品",
				"overlap": false,
				"personalCoupon": false,
				"platform": 0,
				"plusCoupon": false,
				"quota": 359,
				"roleId": 83799595,
				"timeDesc": "有效期2022-08-16至2022-08-19",
				"toUrl": "mall.jd.com/index-213251.html",
				"userRiskLevel": 5
			},
			{
				"addDays": 0,
				"anotherType": 0,
				"applicability": true,
				"area": 1,
				"batchId": 870655643,
				"beginTime": "2022.08.16",
				"couponId": "870655643",
				"couponKind": 2,
				"couponStyle": 0,
				"couponType": 1,
				"discount": 20,
				"discountText": "以下商品可使用满259减20的优惠券",
				"encryptedKey": "g6ufiad1ec2007244208ad2d90917ef1",
				"endTime": "2022.08.19",
				"labelTxt": "店铺东券",
				"limitType": 5,
				"milliSecond": 0,
				"multipleDiscount": false,
				"name": "仅可购买安踏悠购专卖店商品",
				"overlap": false,
				"personalCoupon": false,
				"platform": 0,
				"plusCoupon": false,
				"quota": 259,
				"roleId": 83799545,
				"timeDesc": "有效期2022-08-16至2022-08-19",
				"toUrl": "mall.jd.com/index-213251.html",
				"userRiskLevel": 5
			},
			{
				"addDays": 0,
				"anotherType": 0,
				"applicability": true,
				"area": 1,
				"batchId": 911562141,
				"beginTime": "2022.08.07",
				"couponId": "911562141",
				"couponKind": 2,
				"couponStyle": 0,
				"couponType": 1,
				"discount": 10,
				"discountText": "以下商品可使用满99减10的优惠券",
				"encryptedKey": "gcufiad7ec210a2e41ca41c99322dbd1",
				"endTime": "2022.08.25",
				"labelTxt": "店铺东券",
				"limitType": 5,
				"milliSecond": 0,
				"multipleDiscount": false,
				"name": "仅可购买安踏悠购专卖店商品",
				"overlap": false,
				"personalCoupon": false,
				"platform": 0,
				"plusCoupon": false,
				"quota": 99,
				"roleId": 83168886,
				"timeDesc": "有效期2022-08-07至2022-08-25",
				"toUrl": "mall.jd.com/index-213251.html",
				"userRiskLevel": 5
			}
		]
	},
	"error": "",
	"reason": "",
	"error_code": "0000",
	"cache": 0,
	"api_info": "today:31 max:10100 all[82=31+31+20];expires:2030-12-31",
	"execution_time": "0.367",
	"server_time": "Beijing/2022-08-19 09:30:33",
	"client_ip": "106.6.39.33",
	"call_args": [],
	"api_type": "jd",
	"translate_language": "zh-CN",
	"translate_engine": "google_new",
	"server_memory": "3.47MB",
	"request_id": "gw-1.62fee7b8e378a",
	"last_id": "1160799832"
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码的优化可以从以下几个方面进行: 1. 将元素定位的代码封装成一个单独的方法,以提高代码的可读性和可维护性。 2. 将等待时间配置成一个配置文件,以方便后续修改。 3. 使用CSS选择器代替XPath选择器,因为CSS选择器的速度更快。 4. 在等待元素出现时,可以添加一个时间戳,超过时间戳就抛出异常,避免无限等待的情况出现。 下面是优化后的代码: ``` class CouponVerification: def __init__(self, driver): self.driver = driver self.wait = WebDriverWait(self.driver, timeout=config.TIMEOUT) self.select_store_button = self.find_element(By.XPATH, '元素的xpath') self.select_store_input = self.find_element(By.CSS_SELECTOR, 'div.index-module_account-select-search-wrapper__pWNeA input.life-core-input') self.store_button = self.find_element(By.CSS_SELECTOR, ".index-module_account-select-item-pc__text__G0o02:first-child") self.coupon_input = self.find_element(By.XPATH, '//input[@placeholder="请输入12-15位数字券码"]') self.coupon_button = self.find_element(By.XPATH, '//div[@class="src-pages-HomeV2-components-VerificationV2-index-module__submitBtn--phChf--212e2"]') def find_element(self, method, element): timestamp = time.time() while time.time() - timestamp < config.TIMEOUT: try: if method == By.XPATH: return self.wait.until(EC.visibility_of_element_located((method, element))) else: return self.wait.until(method((method, element))) except TimeoutException: continue raise TimeoutException("元素在页面中不可见") ``` 需要注意的是,这里使用了一个配置文件config.py,其中包含了等待时间的配置,可以根据具体需求进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值