获取1688最新热门商品信息为例,需要进行以下操作:
首先需要在开放平台申请开发者账号,并创建应用。开发者账号审核通过后,即可获得自己个人专属的Api Key和Api Secret,这些参数需要妥善存储,不要泄露。
使用Api Key和Api Secret参考开放平台文档进行授权。
2.调用接口
使用获取到的Api Key和Api Secret调用1688的商品搜索接口进行商品数据采集。
需要填写的参数为:
-
参数说明
- 通用参数说明
- version:API版本
- key:调用key,测试key:test_api_key
- secret:调用secret,测试secret:(不用填写)
- cache:[yes,no]默认yes,将调用缓存的数据,速度比较快
- result_type:[json,xml,serialize,var_export]返回数据格式,默认为json
- lang:[cn,en,ru] 翻译语言,默认cn简体中文
- secret:密钥
-
API:item_search 参数说明:
- q:搜索关键字
- cat:分类ID
- start_price:开始价格
- end_price:结束价格
- sort:排序[bid,bid,bid2,_bid2,_sale,_credit]
(bid:总价,bid2:商品价格,sale:销量,credit信用,加前缀为从大到小排序) - page:页数
- page_size:每页宝贝数量,默认40
- seller_info:是否获取商家信息[yes,no],默认yes
-
API:item_get 参数说明: num_iid:宝贝ID
PHP请求示例
<?php // 请求示例 url 默认请求参数已经URL编码处理 // 本示例代码未加密secret参数明文传输,若要加密请参考:https://open.onebound.cn/help/demo/sdk/demo-sign.php $method = "GET"; $url = "https://1688/item_search/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&q=女装&start_price=0&end_price=0&page=1&cat=0&discount_only=&sort=&page_size=40&seller_info=no&nick=&seller_info=&nick=&ppath=&imgid=&filter="; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,FALSE); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_ENCODING, "gzip"); var_dump(curl_exec($curl)); ?>
代码演示示例
{ "items": { "page": "1", "real_total_results": 700, "total_results": 700, "page_size": 0, "pagecount": 100, "item": [ { "title": "Nuls裸感无袖网球裙春夏新款收腰显瘦连衣运动裙女双层防晒荷叶裙", "pic_url": "https://cbu01.alicdn.com/img/ibank/O1CN01nSBNSN2EvezZ0pQzM_!!991938807-0-cib.jpg", "promotion_price": "63.16", "price": "55", "sales": 259, "turnover": "254", "num_iid": "718759277133", "seller_nick": "浙江爱度服饰有限公司", "tag_percent": "16.3%", "area": "义乌市", "detail_url": "https://detail.1688.com/offer/718759277133.html" }, { "title": "亚马逊欧美抽绳辣妹裙子夏新款 修身无袖连衣裙通勤 松紧包臀皮裙", "pic_url": "https://cbu01.alicdn.com/img/ibank/O1CN01LjKlWF2DKjR0FPuaT_!!2214635688591-0-cib.jpg", "promotion_price": "43.5", "price": "36.1", "sales": 7093, "turnover": "3", "num_iid": "686095433106", "seller_nick": "温州青衫服饰有限公司", "tag_percent": "28.8%", "area": "温州市", "detail_url": "https://detail.1688.com/offer/686095433106.html" }, { "title": "夏季修身显瘦包臀短裙子职业装气质藏蓝通勤连衣裙前台经理工作服", "pic_url": "https://cbu01.alicdn.com/img/ibank/O1CN019eW9O523Xsf3XUwEr_!!2215931977266-0-cib.jpg", "promotion_price": "320", "price": "320", "sales": 0, "turnover": "0", "num_iid": "723523330227", "seller_nick": "成都佰雅琪服装有限公司", "tag_percent": null, "area": "成都市", "detail_url": "https://detail.1688.com/offer/723523330227.html" }, { "title": "Nuls裸感无袖网球裙春夏新款收腰显瘦连衣运动裙女双层防晒荷叶裙", "pic_url": "https://cbu01.alicdn.com/img/ibank/O1CN01nSBNSN2EvezZ0pQzM_!!991938807-0-cib.jpg", "promotion_price": "63.16", "price": "55", "sales": 259, "turnover": "254", "num_iid": "718759277133", "seller_nick": "浙江爱度服饰有限公司", "tag_percent": "16.3%", "area": "义乌市", "detail_url": "https://detail.1688.com/offer/718759277133.html" }, { "title": "亚马逊欧美抽绳辣妹裙子夏新款 修身无袖连衣裙通勤 松紧包臀皮裙", "pic_url": "https://cbu01.alicdn.com/img/ibank/O1CN01LjKlWF2DKjR0FPuaT_!!2214635688591-0-cib.jpg", "promotion_price": "43.5", "price": "36.1", "sales": 7093, "turnover": "3", "num_iid": "686095433106", "seller_nick": "温州青衫服饰有限公司", "tag_percent": "28.8%", "area": "温州市", "detail_url": "https://detail.1688.com/offer/686095433106.html" }, { "title": "夏季修身显瘦包臀短裙子职业装气质藏蓝通勤连衣裙前台经理工作服", "pic_url": "https://cbu01.alicdn.com/img/ibank/O1CN019eW9O523Xsf3XUwEr_!!2215931977266-0-cib.jpg", "promotion_price": "320", "price": "320", "sales": 0, "turnover": "0", "num_iid": "723523330227", "seller_nick": "成都佰雅琪服装有限公司", "tag_percent": null, "area": "成都市", "detail_url": "https://detail.1688.com/offer/723523330227.html" }, { "title": "佰雅琪职业装夏季女士前台行政导购销售职业连衣裙定制生产厂家", "pic_url": "https://cbu01.alicdn.com/img/ibank/O1CN01lApzS623Xsf3VFMiY_!!2215931977266-0-cib.jpg", "promotion_price": "220", "price": "220", "sales": 0, "turnover": "0", "num_iid": "723347557548", "seller_nick": "成都佰雅琪服装有限公司", "tag_percent": null, "area": "成都市", "detail_url": "https://detail.1688.com/offer/723347557548.html" } ], "data_from": "app" }, "error_code": "0000", "reason": "ok", "secache": "f3169c714a064343dac5321a7070e76c", "secache_time": 1686556780, "secache_date": "2023-06-12 15:59:40", "translate_status": "", "translate_time": 0, "language": { "default_lang": "cn", "current_lang": "cn" }, "error": "", "cache": 0, "api_info": "today:120 max:10000 all[269=120+43+106];expires:2030-12-31", "execution_time": "1.006", "server_time": "Beijing/2023-06-12 15:59:40", "client_ip": "220.177.180.237", "call_args": { "q": "女装", "start_price": "0", "end_price": "0", "page": "1", "cat": "0", "page_size": "40" }, "api_type": "1688", "translate_language": "zh-CN", "translate_engine": "baidu", "server_memory": "4.1MB", "request_id": "gw-1.6486d06b21e6e", "last_id": "1801937416" }
通过调用该接口,即可获取到1688最新热门商品信息。
需要注意的是,调用API接口需要根据API文档提供的规则和参数进行调用,并根据返回结果进行解析。不同API接口的调用方式和返回结果可能会有所不同,需要根据具体情况进行调整。
标签:url,price,采集,API,https,curl,com,页面 From: https://www.cnblogs.com/Cris20230328/p/17475298.html