/** * 探针脚本(第四轮):确认中证官网 PE 口径(静态 vs 滚动 TTM) * 中证500:index-perf 的 peg=26.53,蛋卷 pe=34.75,需确认 peg 是哪种口径 * 思路: * 1. 中证官网每日 xls 文件(含 市盈率1/市盈率2 两个口径) * 2. 中证官网其他含估值字段的接口 * 用法:node dev_test_scripts/debug/debug_dip_eval_sources4.js */ const axios = require('axios') const UA = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36' } ;(async () => { // 1. 中证官网 xls 每日文件(二进制,先看响应头与体积,再尝试文本化找市盈率列) for (const code of ['000300', '000905']) { try { const url = `https://csi-web-dev.oss-cn-shanghai-finance-1-pub.aliyuncs.com/static/html/csindex/public/uploads/file/autofile/perf/${code}perf.xls` const res = await axios.get(url, { timeout: 20000, responseType: 'arraybuffer', headers: UA, validateStatus: () => true }) const buf = Buffer.from(res.data) console.log(`[xls ${code}] status=${res.status} bytes=${buf.length}`) // xls 内文本片段(GBK),找“市盈率”附近的数字 let text = '' try { text = require('iconv-lite').decode(buf, 'gb18030') } catch { text = buf.toString('latin1') } const idx = text.indexOf('市盈率') if (idx >= 0) { console.log(`[xls ${code}] 表头附近: ${text.slice(Math.max(0, idx - 60), idx + 120).replace(/[^\x20-\x7E\u4e00-\u9fff,。.\-\r\n]/g, ' ')}`) // 最后一行数据(最新日期行) const lines = text.split(/\r?\n/).filter(l => /\d{4}\/\d{1,2}\/\d{1,2}|\d{8}/.test(l)) if (lines.length) console.log(`[xls ${code}] 最新数据行: ${lines[lines.length - 1].replace(/[^\x20-\x7E\u4e00-\u9fff,。.\-\r\n]/g, ' ').slice(0, 300)}`) } else { console.log(`[xls ${code}] 未找到“市盈率”字样,前200字节hex=${buf.slice(0, 100).toString('hex')}`) } } catch (e) { console.log(`[xls ${code}] 异常: ${e.message}`) } } // 2. 中证官网其他可能的估值接口 const candidates = [ 'https://www.csindex.com.cn/csindex-home/perf/index-perf-detail?indexCode=000905', 'https://www.csindex.com.cn/csindex-home/index/valuation?indexCode=000905', 'https://www.csindex.com.cn/csindex-home/index/index-detail?indexCode=000905' ] for (const url of candidates) { try { const res = await axios.get(url, { timeout: 15000, headers: { ...UA, 'Referer': 'https://www.csindex.com.cn/' }, validateStatus: () => true }) console.log(`[接口探测] ${url}\n status=${res.status} body=${JSON.stringify(res.data).slice(0, 400)}`) } catch (e) { console.log(`[接口探测] ${url} 异常: ${e.message}`) } } })()