import requests
#ecoding=utf-8
import xlsxwriter
import xlwt
# import random
cookies = {
'_zcy_log_client_uuid': '417f98d0-8d0b-11eb-aad4-1bddb336a40f',
'UM_distinctid': '178670c00bbbe-0c368a32a08607-5c3f1d4d-144000-178670c00bc9a',
'CNZZDATA1259303436': '594600627-1616632243-https%253A%252F%252Fmiddle.zcygov.cn%252F%7C1616632243',
'aid': '331023',
'platform_code': 'qyg',
'SESSION': 'MDM0NjJjMmYtZjBjNi00MTFhLTljZmYtMTQ5NGIxMDAzODIx',
'wsid': '1000437735#1621653367023',
'uid': '10007092713',
'user_type': '0202',
'tenant_code': '331023',
'institution_id': '1000412972',
'districtCode': '331023',
'districtName': '%E5%A4%A9%E5%8F%B0%E5%8E%BF',
'session_application_code': 'zcy.agreement',
'acw_tc': '76b20ff716216675202012828e286e81f0dd4be9f1d2e1d93f6318fa5e5e64',
}
headers = {
'Connection': 'keep-alive',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Microsoft Edge";v="90"',
'Accept': 'application/json, text/plain, */*',
'X-Requested-With': 'XMLHttpRequest',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66',
'Content-Type': 'application/json;charset=UTF-8',
'Origin': 'https://www.zcygov.cn',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://www.zcygov.cn/eevees/shop?shopId=125241&searchType=1&utm=a0004.eevees-supplierlist.c0002.2.2b564f30baac11eb97e76be89e45d174',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
}
data = '{"pageNo":1,"pageSize":50,"searchType":1,"shopId":"125241","hasStock":true,"deliveryCode":331023,"normal":6,"instanceCode":"ZJWC"}'
response = requests.post('https://www.zcygov.cn/front/index/search/search', headers=headers, cookies=cookies, data=data)
baba = response.json()
dd = baba["result"]["searchWithAggs"]["entities"]["data"]
print(dd)
print(dd[0]["attributes"])
f = xlwt.Workbook()
ws = f.add_sheet(r'sheet1', cell_overwrite_ok=True)
for i in range(50): #控制列
for j in range(11): #控制行
#第一列
if (j == 0):
ws.write(i, j, dd[i]["price"])
if (j == 1):
ws.write(i, j, dd[i]["brandName"])
if (j >= 2 & j <= 9):
len1 = len(dd[i]["attributes"])
for k in range(len1-1):
ws.write(i, k+2, dd[i]["attributes"][k])
if (j == 10):
ws.write(i, j, dd[i]["backCategoryName"])
f.save('C:/Users/xxx/Desktop/报价单2.xls')
爬虫商品信息,并生成表格
最新推荐文章于 2024-08-06 11:36:33 发布