Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/routes/ebay/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'eBay',
url: 'ebay.com',
categories: ['shopping'],
description: 'eBay search results and user listings.',
};
72 changes: 72 additions & 0 deletions lib/routes/ebay/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { load } from 'cheerio';

import type { Route } from '@/types';
import logger from '@/utils/logger';
import ofetch from '@/utils/ofetch';

export const route: Route = {
path: '/search/:keywords',
categories: ['shopping'],
example: '/ebay/search/sodimm+ddr4+16gb',
parameters: { keywords: 'Keywords for search' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['ebay.com/sch/i.html'],
target: (params, url) => {
const searchKeywords = new URL(url).searchParams.get('_nkw');
return `/ebay/search/${searchKeywords}`;
},
},
],
name: 'Search Results',
maintainers: ['phoeagon'],
handler: async (ctx) => {
const { keywords } = ctx.req.param();
const url = `https://www.ebay.com/sch/i.html?_nkw=${encodeURIComponent(keywords)}&_sop=10&_ipg=240`;

const response = await ofetch(url);
const $ = load(response);

const items = $('.srp-results .s-item, .srp-results .s-card, .s-card')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#21323 (comment)

If removing the selector does work then don't include it in the first place as this means it is redundant.

.toArray()
.map((item) => {
const $item = $(item);
const titleElement = $item.find('.s-item__title, .s-card__title, .s-item__title--has-tags');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide an example that the site does have .s-item__title or .s-item__title--has-tags in its CSS classname?

const title = titleElement.text().replace(/^new listing/i, '').trim();
const link = $item.find('.s-item__link, .s-card__link').attr('href');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide an example that the site does have .s-item__link in its CSS classname?

const price = $item.find('.s-item__price, .s-card__price').text().trim();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide an example that the site does have .s-item__price in its CSS classname?

const imageElement = $item.find('.s-item__image-img img, img.s-item__image-img, .s-item__image-wrapper img, .s-card__image-img img, .s-item__image img, .s-card__link img');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide an example that the site does have .s-item__image-img, .s-item__image-wrapper, .s-item__image or .s-card__image-img in its CSS classname?

const image = imageElement.attr('data-src') || imageElement.attr('src');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide an example that the site does have img URLs appears only in the data-src attribute?


if (!title || !link || title.toLowerCase().includes('shop on ebay') || price === '') {
return null;
}

const cleanedLink = new URL(link);
cleanedLink.search = '';

return {
title: `${title} - ${price}`,
link: cleanedLink.toString(),
description: `<img src="${image?.replace(/\.jpe?g$/i, '.webp')}"><br>Price: ${price}`,
};
})
.filter(Boolean);

logger.info(`Found ${items.length} items on eBay`);

return {
title: `eBay Search: ${keywords}`,
link: url,
item: items,
};
},
};
65 changes: 65 additions & 0 deletions lib/routes/ebay/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { load } from 'cheerio';

import type { Route } from '@/types';
import ofetch from '@/utils/ofetch';

export const route: Route = {
path: ['/user/:username'],
categories: ['shopping'],
example: '/ebay/user/m.trotters',
parameters: { username: 'Username of the seller' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['ebay.com/usr/'],
target: '/user/:username',
},
],
name: 'User Listings',
maintainers: ['phoeagon'],
handler: async (ctx) => {
const { username } = ctx.req.param();
const url = `https://www.ebay.com/usr/${username}`;

const response = await ofetch(url);
const $ = load(response);

const items = $('article.str-item-card.StoreFrontItemCard')
.toArray()
.map((item) => {
const $item = $(item);
const title = $item.find('.str-card-title .str-text-span').first().text().trim();
const link = $item.find('.str-item-card__link').attr('href');
const price = $item.find('.str-item-card__property-displayPrice').text().trim();
const image = $item.find('.str-image img').attr('src');

if (!title || !link) {
return null;
}

const cleanedLink = new URL(link);
cleanedLink.search = '';

return {
title: `${title} - ${price}`,
link: cleanedLink.toString(),
description: `<img src="${image?.replace(/\.jpe?g$/i, '.webp')}"><br>Price: ${price}`,
author: username,
};
})
.filter(Boolean);

return {
title: `eBay User: ${username}`,
link: url,
item: items,
};
},
};
Loading