##!/usr/bin/python3 #coding=utf-8 import json import random import requests # {preferenceId: 32, preferenceName: "卷板"} # # {preferenceId: 33, preferenceName: "中板"} # # {preferenceId: 34, preferenceName: "建材"} # # {preferenceId: 35, preferenceName: "大中型材"} # # {preferenceId: 36, preferenceName: "H型钢"} # # {preferenceId: 37, preferenceName: "无缝管"} # # {preferenceId: 38, preferenceName: "直缝焊管"} # # {preferenceId: 39, preferenceName: "结构钢"} headers = { 'Accept': '*/*', 'Accept-Language': 'zh,zh-CN;q=0.9,en;q=0.8', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'From': '1', 'Origin': 'https://hq.zgw.com', 'Referer': 'https://hq.zgw.com/', 'RequestNo': '0.6919234135022463', 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-site', 'Time': '1675229697000', 'Token': 'eea1afafe66068eac0b516c47450f166', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36', 'sec-ch-ua': '"Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"macOS"', } # 替换参数即可 data = { 'preferenceId': '33', 'memberID': '0', } response = requests.post('https://appv2services.zgw.com/api//WJ/GetTodayPrice', headers=headers, data=data) print(response.text) print(response.content)
接口地址: https://appv2services.zgw.com/api//WJ/GetTodayPrice POST 提交 提交的载荷为 [JavaScript] 纯文本查看 复制代码 { preferenceId: 32, memberID: 0 }
[Python] 纯文本查看 复制代码##!/usr/bin/python3 #coding=utf-8 import json import requests import csv # {preferenceId: 32, preferenceName: "卷板"} # # {preferenceId: 33, preferenceName: "中板"} # # {preferenceId: 34, preferenceName: "建材"} # # {preferenceId: 35, preferenceName: "大中型材"} # # {preferenceId: 36, preferenceName: "H型钢"} # # {preferenceId: 37, preferenceName: "无缝管"} # # {preferenceId: 38, preferenceName: "直缝焊管"} # # {preferenceId: 39, preferenceName: "结构钢"} if __name__ == '__main__': with open("./zgw.csv", "a+", newline='') as csvfile: csv_file = csv.writer(csvfile) headers = { 'Accept': '*/*', 'Accept-Language': 'zh,zh-CN;q=0.9,en;q=0.8', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'From': '1', 'Origin': 'https://hq.zgw.com', 'Referer': 'https://hq.zgw.com/', 'RequestNo': '0.6919234135022463', 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-site', 'Time': '1675229697000', 'Token': 'eea1afafe66068eac0b516c47450f166', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36', 'sec-ch-ua': '"Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"macOS"', } # 替换参数即可 data = { 'preferenceId': '32', 'memberID': '0', } response = requests.post('https://appv2services.zgw.com/api//WJ/GetTodayPrice', headers=headers, data=data) json_text = json.loads(response.text) cityList = json_text["data"]["cityList"] priceTypeDetailList = json_text["data"]["priceTypeDetailList"] citystr = [] for cityjson in cityList: citystr.append(cityjson["cityName"]) print(citystr) for term in priceTypeDetailList: title=term['title'] print(term['title']) priceDetailList = term['priceDetailList'] for dates in priceDetailList: date=dates['date'] print(dates['date']) priceList=dates['priceList'] print(dates['priceList']) titles=[] titles.append(date) titles.append(title) csv_file.writerow(titles) csv_file.writerow(citystr) csv_file.writerow(priceList) csvfile.flush() # 大致写的,需要修改的话你自己调整