lefengyang
2026-08-20 d01a28cb030b2cb0ff1d42273c877a0f728519a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import {parse} from "node-html-parser";
 
export interface INextProps {
    initialState?: {
        item?: {
            detail?: {
                item?: any
            }
        },
        itemsState?: {
            items?: {
                item?: any
            }
        }
    },
    pageProps?: any
}
 
export function queryNextData(htmlStr: string): INextProps {
    try {
        return JSON.parse(parse(htmlStr).querySelector('#__NEXT_DATA__[type*="application/json"]').text?.trim())?.props || {};
    } catch (e) {
        return {};
    }
}