https://www.bilibili.com/video/BV1qU4y1f7qT?spm_id_from=333.337.search-card.all.click
标题/原价/售价/折扣/品牌/详情页/
import requests
import re
import os
import json
import pprint
import csv
############ filednames 傻逼了 应该是
f = open('口红.csv',mode = 'a' , encoding = 'utf-8' , newline = '')
csv_writer = csv.DictWriter(f,fieldnames = ['标题','品牌','原价','售价','折扣','详情页'])
csv_writer.writeheader()#写入包头
headers = {
#':authority': 'mapi.vip.com',
#':method': 'GET',
#':path': '/vips-mobile/rest/shopping/pc/search/product/rank?callback=getMerchandiseIds&app_name=shop_pc&app_version=4.0&warehouse=VIP_NH&fdc_area_id=104104101&client=pc&mobile_platform=1&province_id=104104&api_key=70f71280d5d547b2a7bb370a529aeea1&user_id=&mars_cid=1652794500297_7b42dd7974279ddbea1b6e2b0a575788&wap_consumer=a&standby_id=nature&keyword=%E5%8F%A3%E7%BA%A2&lv3CatIds=&lv2CatIds=&lv1CatIds=&brandStoreSns=&props=&priceMin=&priceMax=&vipService=&sort=0&pageOffset=0&channelId=1&gPlatform=PC&batchSize=120&_=1652794524003',
#':scheme': 'https',
#'accept': '*/*',
#'accept-encoding': 'gzip, deflate, br',
#'accept-language': 'zh,zh-CN;q=0.9',
'cookie': 'vip_cps_cuid=CU165279449587793edb434169899526; vip_cps_cid=1652794495879_6c8a3139896641a32efa42bcf4622ee2; cps_share=cps_share; vip_wh=VIP_NH; cps=adp%3Antq8exyc%3A%40_%401652794495879%3Amig_code%3A4f6b50bf15bfa39639d85f5f1e15b10f%3Aac014miuvl0000b5sq8cpa5ch0xed9ic; PAPVisitorId=30ac936a0f28d13ddf40314c0c292137; vip_new_old_user=1; vip_address=%257B%2522pname%2522%253A%2522%255Cu5e7f%255Cu4e1c%255Cu7701%2522%252C%2522pid%2522%253A%2522104104%2522%252C%2522cname%2522%253A%2522%255Cu5e7f%255Cu5dde%255Cu5e02%2522%252C%2522cid%2522%253A%2522104104101%2522%257D; vip_province=104104; vip_province_name=%E5%B9%BF%E4%B8%9C%E7%9C%81; vip_city_name=%E5%B9%BF%E5%B7%9E%E5%B8%82; vip_city_code=104104101; user_class=a; mars_sid=124ab7218870623e7d123edd279d72f6; mars_pid=0; visit_id=DEC4888BE5ECF29E23C5278BD47B1C25; VipUINFO=luc%3Aa%7Csuc%3Aa%7Cbct%3Ac_new%7Chct%3Ac_new%7Cbdts%3A0%7Cbcts%3A0%7Ckfts%3A0%7Cc10%3A0%7Crcabt%3A0%7Cp2%3A0%7Cp3%3A1%7Cp4%3A0%7Cp5%3A0%7Cul%3A3105; vip_access_times=%7B%22list%22%3A1%7D; pg_session_no=4; vip_tracker_source_from=; mars_cid=1652794500297_7b42dd7974279ddbea1b6e2b0a575788',
'referer': 'https://category.vip.com/',
#'sec-fetch-dest': 'script',
#'sec-fetch-mode': 'no-cors',
#'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.188 Safari/537.36 CrKey/1.54.250320',
}
def get_shop_info(productids):
url_1 = 'https://mapi.vip.com/vips-mobile/rest/shopping/pc/product/module/list/v2'
params_1 = {
#'callback': 'getMerchandiseDroplets3',
'app_name': 'shop_pc',
'app_version': '4.0',
'warehouse': 'VIP_NH',
'fdc_area_id': '104104101',
'client': 'pc',
'mobile_platform': '1',
'province_id': '104104',
'api_key': '70f71280d5d547b2a7bb370a529aeea1',
'user_id': '',
'mars_cid': '1652794500297_7b42dd7974279ddbea1b6e2b0a575788',
'wap_consumer': 'a',
'productIds': productids,
'scene': 'search',
'standby_id': 'nature',
'extParams': '{"stdSizeVids":"","preheatTipsVer":"3","couponVer":"v2","exclusivePrice":"1","iconSpec":"2x","ic2label":1}',
'context': '',
'_': '1652794524012',
}
response_1 = requests.get(url=url_1,headers=headers,params=params_1)
json_data_1 = response_1.json()['data']['products']
#pprint.pprint(json_data_1)
#https://detail.vip.com/detail-1710615840-6919459434628041152.html
#https://detail.vip.com/detail-1711548037-6919196993313397061.html
for link in json_data_1:
link_url = 'https://detail.vip.com/detail-' + str(link['brandId']) + '-' + str(link['productId']) + '.html'
dic = {
'标题': link['title'],
'品牌': link['brandShowName'],
'原价': link['price']['marketPrice'],
'售价': link['price']['salePrice'],
'折扣': link['price']['saleDiscount'],
'详情页': link_url,
}
csv_writer.writerow(dic)
print(dic)
#pprint.pprint(link)
#break
https://search.kaola.com/category/3692/7441.html?spm=a2v0d.b49167986.0.0.3aaa2825R7GRzO&key=&pageSize=60&pageNo=3&sortfield=0&isStock=false&isSelfProduct=false&isPromote=false&isTaxFree=false&factoryStoreTag=-1&isCommonSort=false&isDesc=true&b=&proIds=&source=false&country=&needBrandDirect=false&isNavigation=0&lowerPrice=-1&upperPrice=-1&backCategory=&headCategoryId=&#topTab
https://search.kaola.com/category/3692/7441.html?spm=a2v0d.b49167986.0.0.13fa2825rY8loG&key=&pageSize=60&pageNo=2&sortfield=0&isStock=false&isSelfProduct=false&isPromote=false&isTaxFree=false&factoryStoreTag=-1&isCommonSort=false&isDesc=true&b=&proIds=&source=false&country=&needBrandDirect=false&isNavigation=0&lowerPrice=-1&upperPrice=-1&backCategory=&headCategoryId=&#topTab
https://goods.kaola.com/product/9362435.html?spm=a2v0d.b49167986.0.0.20622825nx2xet&ri=navigation&from=page0&zn=result&zp=page0-11&position=11&istext=0&srId=a43f5002a63b2633285ab006838bb53c
'brandId': '1710620520',
'brandShowName': 'Armani',
'categoryId': '390698',
'productId': '6918008217668334216',
'title': '阿玛尼臻致丝绒哑光唇釉 #405 6.5ml'
url = 'https://mapi.vip.com/vips-mobile/rest/shopping/pc/search/product/rank'
params = {
#'callback': 'getMerchandiseIds',
'app_name': 'shop_pc',
'app_version': '4.0',
'warehouse': 'VIP_NH',
'fdc_area_id': '104104101',
'client': 'pc',
'mobile_platform': '1',
'province_id': '104104',
'api_key': '70f71280d5d547b2a7bb370a529aeea1',
'user_id': '',
'mars_cid': '1652794500297_7b42dd7974279ddbea1b6e2b0a575788',
'wap_consumer': 'a',
'standby_id': 'nature',
'keyword': '口红',
'lv3CatIds': '',
'lv2CatIds': '',
'lv1CatIds': '',
'brandStoreSns': '',
'props': '',
'priceMin': '',
'priceMax': '',
'vipService': '',
'sort': '0',
'pageOffset': '0',
'channelId': '1',
'gPlatform': 'PC',
'batchSize': '120',
'_': '1652794524003',
}
response = requests.get(url=url,headers=headers,params=params)
json_data = response.json()
pprint.pprint(json_data)
pids = json_data['data']['products']
lis = []
list = [index['pid'] for index in pids]
for index in pids:
pid = index['pid']
lis.append(pid)
print(list)
str_1 = ','.join(list[:50])
str_2 = ','.join(list[50:100])
str_3 = ','.join(list[100:])
list_3 = str_3.split(',')
print(len(list))
print(len(list_3))
print(str_2)
print(str_3)
get_shop_info(str_1)
get_shop_info(str_2)
get_shop_info(str_3)