python爬取唯品会电商网站数据并保存到csv中
def get_info(pid):
html_url = '/vips-mobile/rest/shopping/pc/product/module/list/v2'
params_1 = {
'app_name': 'shop_pc',
'app_version': '4.0',
'warehouse': 'VIP_HZ',
'fdc_area_id': '104102101',
'client': 'pc',
'mobile_platform': '1',
'province_id': '104102',
'api_key': '70f71280d5d547b2a7bb370a529aeea1',
'user_id': '',
'mars_cid': '1616561542264_dbf891698c85094d527273d671f70e8f',
'wap_consumer': 'a',
'productIds': pid,
'scene': 'search',
'standby_id': 'nature',
'extParams': '{"stdSizeVids":"","preheatTipsVer":"3","couponVer":"v2","exclusivePrice":"1","iconSpec":"2x","ic2label":1}',
'context': '',
'_': '1616566409853'
}
response_1 = requests.get(url = html_url ,params= params_1 ,headers =headers)
#(response_1.json())
products_list = response_1.json()['data']['products']
for i in products_list:
# 标题
title = i['title']
# 品牌
show_name = i['brandShowName']
# 原价
marker_price = i['price']['marketPrice']
# 折扣
discount = i['price']['saleDiscount']
# 现价
sale_price = i['price']['salePrice']
print(title,show_name,marker_price,discount,sale_price)