fix: make xianyu notifications per-item with clickable links
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { newPage } from './browser.mjs';
|
||||
import { randomDelay, sleep, waitIfVerification } from './utils.mjs';
|
||||
import { sleep, randomDelay, parsePrice, waitIfVerification } from './utils.mjs';
|
||||
import { enrichItemLinks } from './links.mjs';
|
||||
|
||||
const BASE_SEARCH_URL = 'https://www.goofish.com/search';
|
||||
|
||||
@@ -316,7 +317,7 @@ async function applyRegionFilter(page, regionInput, emitLog) {
|
||||
async function scrapeCurrentPage(page) {
|
||||
await autoScroll(page);
|
||||
|
||||
return page.evaluate(() => {
|
||||
const scraped = await page.evaluate(() => {
|
||||
const items = [];
|
||||
const cards = document.querySelectorAll('a[class*="feeds-item-wrap"]');
|
||||
|
||||
@@ -330,10 +331,13 @@ async function scrapeCurrentPage(page) {
|
||||
const descEl = card.querySelector('[class*="price-desc"]');
|
||||
const sellerWrap = card.querySelector('[class*="seller-text-wrap"]');
|
||||
const imgEl = card.querySelector('img[class*="feeds-image"]');
|
||||
const sourceHref = href.startsWith('http') ? href : `https://www.goofish.com${href}`;
|
||||
const categoryMatch = sourceHref.match(/[?&]categoryId=([^&#]+)/);
|
||||
|
||||
items.push({
|
||||
id: idMatch[1],
|
||||
href: href.startsWith('http') ? href : `https://www.goofish.com${href}`,
|
||||
href: sourceHref,
|
||||
categoryId: categoryMatch ? decodeURIComponent(categoryMatch[1]) : '',
|
||||
title: titleEl?.getAttribute('title') || titleEl?.textContent?.trim() || '',
|
||||
price: priceEl?.textContent?.trim() || '',
|
||||
priceDesc: descEl?.textContent?.trim() || '',
|
||||
@@ -344,6 +348,8 @@ async function scrapeCurrentPage(page) {
|
||||
|
||||
return items;
|
||||
});
|
||||
|
||||
return scraped.map(item => enrichItemLinks(item));
|
||||
}
|
||||
|
||||
async function autoScroll(page) {
|
||||
|
||||
Reference in New Issue
Block a user