废话不多说,直接上代码,如下:
import requests
import json
import re
import pandas as pd
def xxx():
d = {
'13966': '面包烘焙', '6431': '新鲜水果',
'6389': '优质蔬菜', '6426': '海鲜冻品',
'7179': '鲜活水产', '6429': '面点速食',
'7736': '放心鲜肉', '6388': '卤香酱货',
'6428': '蛋奶酒水', '6430': '网红食品',
'6884': '米面粮油', '6865': '调料副食',
'6432': '休息零食', '6957': '生活日用'
}
for key in d:
print(str(key) + ':' + str(d[key]))
requests.packages.urllib3.disable_warnings()
response = requests.get(url='xxx地址路径?page=1&per_page=10000&q%5Bjoin_sale_eq%5D=true&store_ids=9222&taxon_ids='+key,
verify=False,
headers={'Accept': '/',
'Host': 'westore.nhsoft.cn',
'X-Mercury-Slug': 'b7582e77',
'X-Mercury-Store-Id': '9222',
'X-Mercury-Token': '97861e82ea9040729ce8bf88eb3d6982d85a2ab45bc6dc94',
'Accept-Language': 'zh-cn',
'Accept-Encoding': 'gzip, deflate, br',
'Cache-Control': 'no-cache',
'Content-Type': 'application/json; charset=utf-8',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.12(0x17000c2d) NetType/WIFI Language/zh_CN',
'Referer': 'https://servicewechat.com/wxd160864b3344fe94/30/page-frame.html',
'Connection': 'keep-alive'})
pd.DataFrame(json.loads('[' + re.findall(re.compile(r'[[]]', re.S), response.text)[0] + ']')).to_excel(d[key]+'.xls')
if name == 'main':
xxx()
这是一个URL路径携带参数的写法,如有有参数不是直接被URL路径直接携带,就采用如下方式追加json参数进行URL路径拼接参数,如下图片:
![]0{)~NLM4$5OSC(T}VD@B6.png
把代码复制出来,修改成自己要抓包的小程序地址即可,以及相关参数,该功能还能根据相关分类分别导出到Excel表中,仅供参考,谢谢!