目前,我正在使用以下代码为页面上的所有鞋刮https://www.nike.com/w/mens-shoes-nik1zy7ok:
import requests
import json
# I used a placeholder for the anchor parameter
uri = 'https://api.nike.com/cic/browse/v1?queryid=products&country=us&endpoint=product_feed/rollup_threads/v2?filter=marketplace(US)%26filter=language(en)%26filter=employeePrice(true)%26filter=attributeIds(0f64ecc7-d624-4e91-b171-b83a03dd8550%2C16633190-45e5-4830-a068-232ac7aea82c)%26anchor={}%26consumerChannelId=d9a5bc42-4b9c-4976-858a-f159cf99c647%26count=60'
# collect all products
store = []
with requests.Session() as session:
found_all_products = False
anchor = 0
while not found_all_products:
result = session.get(uri.format(anchor)).json()
products = result['data']['products']['products']
store += products
if len(products) < 60:
found_all_products = True
else:
anchor += 24
# filter by cloudProductId to get a dictionary with unique products
cloudProductIds = set()
unique_products = []
for product in store:
if not product['cloudProductId'] in cloudProductIds:
cloudProductIds.add(product['cloudProductId'])
unique_products.append(product)
我如何编写相同的api请求从该站点检索男鞋或在女鞋页面检索女鞋:https://www.nike.com/w/womens-shoes-5e1x6zy7ok?我需要更改哪个参数
@Greg我在《邮差》中运行了你提供的API链接,得到了不同的结果,分别针对男性和女性。我在查询字符串参数中所做的所有更改都是UUIDs,这在男性和女性的情况下都是独一无二的:0f64ecc7-d624-4e91-b171-B83A03DD855016633190-45e5-4830-a068-232ac7aea82cUUIDs:16633190-45e5-4830-a068-232ac7aea82c,193af413-39b0-4d7e-ae34-558821381d3f,7baf216c-acc6-4452-9e07-39c2ca77ba32
如果您在查询字符串中传递这两组唯一的UUID,那么您将分别得到男性和女性的结果,因为没有其他参数来定义他们的身份
代码如下:
如果您查看我为男性和女性创建的查询字符串,您会注意到有6个公共参数,只有uuid是唯一的。如果您愿意,还可以更改国家、语言等以获取更多数据。请同时参考屏幕截图
男人
女性
相关问题 更多 >
编程相关推荐