[Python] 纯文本查看 复制代码
import requests
import hashlib
import json
import random
import time
from urllib.parse import quote
from curl_cffi import requests
import pymysql
from jsonpath_ng import jsonpath, parse
import re
from email.mime.text import MIMEText
from email.header import Header
import smtplib
import threading
from datetime import datetime
from tenacity import retry, stop_after_attempt, wait_fixed
import re
url = "https://api2.kkzhw.com/mall-search/kkSearch/search?productCategoryId=75&pageNum=1&pageSize=10"
json_data = {"sort": "desc", "order": "publishTime", "queryStrParams": [], "keyword": "", "attrValueList": [
{"name": "账号专区", "ename": "", "selectType": 1, "inputType": 1, "sort": 60000, "filterType": 0, "searchType": 1,
"type": 3, "searchSort": 0, "moreTxt": "展开更多", "value": "在售专区"},
{"name": "职业", "selectType": 1, "inputType": 1, "sort": 40000, "filterType": 1, "searchType": 1, "type": 1,
"searchSort": 0, "nameGroup": "官方截图", "moreTxt": "展开更多", "value": ""},
{"name": "账号类型", "selectType": 1, "inputType": 1, "sort": 31000, "filterType": 0, "searchType": 1, "type": 1,
"searchSort": 0, "nameGroup": "官方截图", "moreTxt": "展开更多", "value": ""},
{"name": "已使用天赏石", "selectType": 0, "inputType": 0, "sort": 24000, "filterType": 0, "searchType": 2,
"type": 1, "searchSort": 5, "nameGroup": "官方截图", "moreTxt": "展开更多", "value": "1-9999999"},
{"name": "未使用天赏石", "selectType": 0, "inputType": 0, "sort": 23999, "filterType": 0, "searchType": 2,
"type": 1, "searchSort": 8, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "性别", "selectType": 1, "inputType": 1, "sort": 23000, "filterType": 0, "searchType": 1, "type": 1,
"searchSort": 0, "nameGroup": "官方截图", "moreTxt": "展开更多", "value": ""},
{"name": "评分", "selectType": 0, "inputType": 0, "sort": 22500, "filterType": 0, "searchType": 2, "type": 1,
"searchSort": 3, "moreTxt": "展开更多", "value": ""},
{"name": "衣品", "selectType": 0, "inputType": 0, "sort": 22000, "filterType": 0, "searchType": 2, "type": 1,
"searchSort": 2, "moreTxt": "展开更多", "value": ""},
{"name": "国色值", "selectType": 0, "inputType": 0, "sort": 9999, "filterType": 0, "searchType": 2, "type": 1,
"searchSort": 1, "moreTxt": "展开更多", "value": ""},
{"name": "换绑CD", "selectType": 1, "inputType": 1, "sort": 9999, "filterType": 0, "searchType": 1, "type": 1,
"searchSort": 0, "nameGroup": "官方截图", "moreTxt": "展开更多", "value": ""},
{"name": "转职CD", "selectType": 1, "inputType": 1, "sort": 9998, "filterType": 0, "searchType": 1, "type": 1,
"searchSort": 0, "nameGroup": "官方截图", "moreTxt": "展开更多", "value": ""},
{"name": "转性CD", "selectType": 1, "inputType": 1, "sort": 9997, "filterType": 0, "searchType": 1, "type": 1,
"searchSort": 0, "nameGroup": "官方截图", "moreTxt": "展开更多", "value": ""},
{"name": "稀有外观", "selectType": 2, "inputType": 1, "sort": 1000, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "moreTxt": "展开更多", "value": ""},
{"name": "稀有道具", "selectType": 2, "inputType": 1, "sort": 900, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "灵韵数量", "selectType": 0, "inputType": 0, "sort": 101, "filterType": 0, "searchType": 2, "type": 1,
"searchSort": 0, "moreTxt": "展开更多", "value": ""},
{"name": "天赏发型", "selectType": 2, "inputType": 1, "sort": 99, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "moreTxt": "展开更多", "value": ""},
{"name": "天赏祥瑞", "selectType": 2, "inputType": 1, "sort": 98, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "moreTxt": "展开更多", "value": ""},
{"name": "天赏技能皮肤", "selectType": 2, "inputType": 1, "sort": 96, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "moreTxt": "展开更多", "value": ""},
{"name": "其他天赏道具", "selectType": 2, "inputType": 1, "sort": 95, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "充值称号", "selectType": 2, "inputType": 1, "sort": 90, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "武器外观", "selectType": 2, "inputType": 1, "sort": 89, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "moreTxt": "展开更多", "value": ""},
{"name": "轻功外观", "selectType": 2, "inputType": 1, "sort": 88, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "绝版外观", "selectType": 2, "inputType": 1, "sort": 87, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "灵韵内功", "selectType": 2, "inputType": 1, "sort": 4, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "极品内功", "selectType": 2, "inputType": 1, "sort": 3, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "moreTxt": "展开更多", "value": ""},
{"name": "金色武器打造", "selectType": 2, "inputType": 1, "sort": 1, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "充值金额", "selectType": 0, "inputType": 0, "sort": 0, "filterType": 0, "searchType": 2, "type": 1,
"searchSort": 0, "moreTxt": "展开更多", "value": ""},
{"name": "金色项链打造", "selectType": 2, "inputType": 1, "sort": 0, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "金色鞋子打造", "selectType": 2, "inputType": 1, "sort": 0, "filterType": 1, "searchType": 3, "type": 2,
"searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""},
{"name": "金色衣服护腕打造", "selectType": 2, "inputType": 1, "sort": 0, "filterType": 1, "searchType": 3,
"type": 2, "searchSort": 0, "nameGroup": "", "moreTxt": "展开更多", "value": ""}]}
headers = {
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
'Content-Type': 'application/json',
'Accept': '*/*',
'Host': 'api2.kkzhw.com',
'Connection': 'keep-alive'
# 'Cookie': 'acw_tc=c8d1b415709a7a7273ee18f900302071e257443c1b145391dccd75990f63a79c'
}
def send_post_request(url, json_data, headers):
response = requests.post(url, json=json_data, headers=headers)
now = str(datetime.now())
status_code = str(response.status_code)
kankan = now + ' ' + status_code
print(f"看看发送请求:{kankan}")
try:
data = json.loads(response.text)
except json.JSONDecodeError as e:
print(f"JSON解码错误: {e}")
data1 = json.loads(json.dumps(response.text))
data_list = data["data"]["list"]
attributes_map = {}
for lst in data_list:
attr_value_list = lst["attrValueList"]
for attr_value in attr_value_list:
attributes_map[attr_value['productAttributeId']] = attr_value['value']
zh = attributes_map.get(108, '')
tnr = attributes_map.get(166, '')
dj = attributes_map.get(301, '')
ly = attributes_map.get(336, '')
jsonpath_expr = parse('$..list[*]')
for match in jsonpath_expr.find(data):
bh = str(match.value['productSn'])
amount = round(int(match.value['price']))
if amount is None:
amount = 0
gs = int(match.value['sortValue1'])
if gs is None:
gs = 0
yp = int(match.value['sortValue2'])
if yp is None:
yp = 0
info_time = str(match.value['publishTime'])
tss1 = int(match.value['sortValue5'])
tss2 = int(match.value['sortValue8'])
tss = tss1 + tss2
nss = str(match.value['description'])
if nss is None:
nss = str(match.value['subTitle'])
dq1 = str(match.value['name'])
dq2 = dq1.split('|')
dq = dq2[1][:4]
rate = round(amount / tss)
product = {'编号': bh,
'大区': dq,
'内容': nss,
'天霓染':tnr,
'天赏石': tss,
'金额': amount,
'天赏石均价': rate,
'发布时间': info_time,
'国色': gs,
'衣品': yp
}
print(product)
send_post_request(url, json_data, headers)