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
import { fetch } from "https://esm.town/v/std/fetch";
interface IDetails {
title: string;
price: number;
url: string;
}
export const njuskaloSniff = async (search = []): Promise<IDetails | undefined> => {
const cheerio = await import("npm:cheerio");
const keywords = search.join("%20");
const searchUrl =
`https://www.njuskalo.hr/?ctl=search_ads&keywords=${keywords}&sort=new`;
const v = await fetch(searchUrl);
const txt = await v.text();
let $ = cheerio?.default?.load?.(txt);
if (!$)
return undefined;
// scrap through HTML
const entryTxt =
".wrap-content-primary:first-of-type .content-main .EntityList-items:first-of-type .EntityList-item:first-of-type ";
const title = $(entryTxt + "h3.entity-title:first-of-type a.link").text();
const url = $(entryTxt + "h3.entity-title:first-of-type a.link").attr("href");
const price = $(entryTxt + ".entity-prices .price-item:first-of-type .price")
.text()
.replace(/\s/g, "")
.replace("\n", "")
.split("€")[0]
.replace(",", ".");
return { title, url, price: Number(price) };
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023