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
26
27
28
29
30
31
32
33
import {IPage, ISearchItem} from "/src-com";
import {parse} from 'node-html-parser';
 
export function parseProducts(docHtml: string): IPage<ISearchItem> {
    const map = new Map();
    const doc = parse(docHtml);
    doc.querySelectorAll('.Products__items .Product')
        .map(parseItem as any)
        .forEach(item => map.set(item.itemId, item));
    const total = parseInt(doc.querySelector('.Tab__item--current .Tab__subText').textContent?.replace(/\D+/g, ''))
    return {
        total: Math.max(total || 0, map.size),
        dataList: Array.from(map.values())
    };
}
 
 
function parseItem(el: HTMLElement): ISearchItem {
    return {
        itemId: el.querySelector('a.Product__imageLink')?.getAttribute('data-auction-id'),
        url: el.querySelector('a.Product__imageLink')?.getAttribute('href'),
        image: {
            imageUrl: el.querySelector('img.Product__imageData')?.getAttribute('src'),
            alt: el.querySelector('img.Product__imageData')?.getAttribute('alt'),
        },
        name: el.querySelector('.Product__title')?.textContent?.trim(),
        bid: el.querySelector('.Product__bid')?.textContent?.trim(),
        time: el.querySelector('.Product__time')?.textContent?.trim(),
        price: parseInt(el.querySelector('.Product__priceInfo .Product__priceValue')?.textContent?.replace(/\D+/g, '')),
        buyItNowPrice: parseInt(el.querySelectorAll('.Product__priceInfo .Product__priceValue')[1]?.textContent.replace(/\D+/g, '')) || -1,
        shippingFee: parseInt(el.querySelector('.Product__priceInfo .Product__postage')?.textContent?.replace(/\D+/g, '')) || 0,
    }
}