2026-03-20 21:53:19 +08:00

91 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const getSpfsjtjData = () => {
const res = {};
const root = document.querySelectorAll('.portlet')[1];
Object.keys(rootDefined.spfsjtj.childMap).forEach((moduleKey, index) => {
res[moduleKey] = {};
const moduleDom = root.querySelectorAll('td table')[index];
const moduleFiledMap = rootDefined.spfsjtj.childMap[moduleKey].childMap;
Object.keys(moduleFiledMap).forEach((fieldKey, fieldIndex) => {
const fieldDom = moduleDom.querySelectorAll('tr')[fieldIndex + 1].querySelectorAll('td')[1];
res[moduleKey][fieldKey] = fieldDom.innerText.trim();
});
});
return res;
}
const getClfwsqytjData = () => {
const res = {};
const root = document.querySelectorAll('.portlet')[2];
Object.keys(rootDefined.clfwsqytj.childMap).forEach((moduleKey, index) => {
res[moduleKey] = {};
const moduleDom = root.querySelectorAll('td table')[index];
const moduleFiledMap = rootDefined.clfwsqytj.childMap[moduleKey].childMap;
Object.keys(moduleFiledMap).forEach((fieldKey, fieldIndex) => {
const fieldDom = moduleDom.querySelectorAll('tr')[fieldIndex + 1].querySelectorAll('td')[1];
res[moduleKey][fieldKey] = fieldDom.innerText.replaceAll(' ', '');
});
});
return res;
}
const getClfwdtjData = () => {
const res = {};
const root = document.querySelectorAll('.portlet')[3];
Object.keys(rootDefined.clfwdtj.childMap).forEach((moduleKey) => {
const tableDomList = root.querySelectorAll('td table');
const moduleFiledMap = rootDefined.clfwdtj.childMap[moduleKey].childMap;
const dataList = [];
if (moduleKey === 'broker') {
// 纵向表格数据在第2、3个table中
const trList = [...tableDomList[1].querySelectorAll('tr')].slice(1).concat([...tableDomList[2].querySelectorAll('tr')].slice(1));
trList.forEach(trDom => {
const dataItem = {};
Object.keys(moduleFiledMap).forEach((fieldKey, fieldIndex) => {
const fieldDom = trDom.querySelectorAll('td')[fieldIndex];
dataItem[fieldKey] = fieldDom.innerText.trim();
});
dataList.push(dataItem);
});
} else if (moduleKey === 'area') {
// 横向表格数据在第5个table中
const trList = [...tableDomList[4].querySelectorAll('tr')];
Object.keys(moduleFiledMap).forEach((fieldKey, fieldIndex) => {
const tdList = [...trList[fieldIndex].querySelectorAll('td')].slice(1);
tdList.forEach((tdDom, tdIndex) => {
if (!dataList[tdIndex]) {
dataList[tdIndex] = {};
}
dataList[tdIndex][fieldKey] = tdDom.innerText.trim();
});
});
} else if (moduleKey === 'district') {
// 横向表格数据在第4个table中叠加在一起每组数组占据3行例如总共9行数据则1-3为第一组4-6为第二组7-9为第三组三组加起来为一个完整的数据项
const trList = [...tableDomList[3].querySelectorAll('tr')];
const groupSize = Object.keys(moduleFiledMap).length; // 每组数据占据的行数
for (let trIndex = 0; trIndex < trList.length; trIndex++) {
const fieldIndex = trIndex % groupSize; // 当前行对应的字段索引
const tdList = [...trList[trIndex].querySelectorAll('td')].slice(1);
const startIndex = Math.floor(trIndex / groupSize) * tdList.length; // 当前组的起始行索引
tdList.forEach((tdDom, tdIndex) => {
if (!dataList[startIndex + tdIndex]) {
dataList[startIndex + tdIndex] = {};
}
const fieldKey = Object.keys(moduleFiledMap)[fieldIndex];
dataList[startIndex + tdIndex][fieldKey] = tdDom.innerText.trim();
});
}
}
res[moduleKey] = dataList;
});
return res;
}
const extractData = () => {
return {
spfsjtj: getSpfsjtjData(),
clfwsqytj: getClfwsqytjData(),
clfwdtj: getClfwdtjData(),
}
}