import * as cheerio from 'cheerio'; import { Stream } from 'node:stream'; /** * The search result interface */ interface ISearchResult { engine: string; link: string; name: string; rating: number; price: number; thumbnail: string; } declare class SearchResult implements ISearchResult { /** * the engine the search was made on */ engine: string; /** * link to the searched product */ link: string; /** * name of the product */ name: string; /** * the rating of the product */ rating: number; /** * price of the product */ price: number; /** * thumbnail of the product */ thumbnail: string; /** * * @param string the engine the search was made on * @param string link to the searched product * @param string name of the product * @param number the rating of the product * @param number price of the product * @param string thumbnail of the product */ constructor(engine: string, link: string, name: string, rating: number, price: number, thumbanil: string); } /** * the output can be in different formats. */ interface IOutput { outputData(searchResults: ISearchResult[]): void; } /** * We scrape a big bunch of different web shops and maybe other systems * that give us prices! */ interface ISearchEngine { search(searchTerm: string): Promise; } declare class ConsoleOutput implements IOutput { /** * Outputs the searched data in the console * @param ISearchResult[] searchResults */ outputData(searchResults: ISearchResult[]): void; } declare class CsvOutput implements IOutput { /** * the path where you wish to save the file */ filePath: string; /** * * @param {string} filePath */ constructor(filePath: string); /** * outputs the data into CSV File * @param ISearchResult[] searchResults */ outputData(searchResults: ISearchResult[]): void; } declare class JSONOutput implements IOutput { /** * the path where you wish to save the file */ filePath: string; /** * * @param string the path where you wish to save the file */ constructor(filePath: string); /** * outputs the data into a json file * @param {ISearchResult[]} searchResults */ outputData(searchResults: ISearchResult[]): void; } declare type HTTPMethods = 'get' | 'post' | 'put' | 'delete' | 'patch'; interface IFetchOptions { /** * http(s).Agent instance or function that returns an instance */ agent?: (_parsedURL: any) => void; /** * request headers. format is the identical to that accepted by the Headers constructor */ headers?: { 'User-Agent': string; }; /** * The HTTP Method of the request */ method?: HTTPMethods; /** * set to `manual` to extract redirect headers, `error` to reject redirect. Default "follow" */ redirect?: string; /** * maximum response body size in bytes. 0 to disable */ size?: number; /** * support gzip/deflate content encoding. false to disable */ compress?: boolean; /** * request body. can be null, a string, a Buffer, a Blob, or a Node.js Readable stream */ body?: null | string | Buffer | Blob | Stream; } declare abstract class SearchEngineBase implements ISearchEngine { abstract search(searchTerm: string): Promise; /** * Fetches the website content and convert its content into text. * @param string baseUrl baseUrl of the site to fetch * @param string searchQuery string of the product you wish to search for * @returns Promise * * Example: * ```ts * const $ = await requestWebsite("https://www.amazon.de/s?k=", "airpods") * // => will return cheerio API Object to work with. * * $(".prices").each((_, value) => { * console.log($(value).text().trim()); * }); * ``` */ protected requestWebsite(baseUrl: string, fetchOptions?: IFetchOptions): Promise; /** * It iterates over all matching results based on the selector and returns an Array containg the texts. * @param cheerio.CheerioAPI $ cheerio.CheerioAPI * @param string selector HTML Selector * @returns string[] Array containing all matched results */ protected collectText($: cheerio.CheerioAPI, selector: string): string[]; /** * It iterates over the selector and returns an array containing the content of the attribute that was provided. * @param cheerio.CheerioAPI $ cheerio.CheerioAPI * @param string selector HTML Selector * @param string attr HTML Attribute Name * @param string baseUrl baseUrl of the website in case you want to get the relative urls of all products * @returns string[] Array containing all matched results */ protected collectLinks($: any, selector: string, attr: string, baseUrl?: string): string[]; /** * Splits a string from whitespace and replaces "," with ".". Used for some online shops. * @param string value * @returns string */ grabFirstPartAsNumber(value: string): any; /** * Returns only unique values from an Array. Used mostly with the filter array method as a callback function. * @param string value * @param number index * @param string self * @returns */ protected onlyUnique(value: string, index: number, self: string | any[]): boolean; /** * Splices an array content based on the given start and endpositions. Returns the original mutated array. * @param string[] array the original array you want to splice/mutate * @param number startPosition where to start splicing the array * @param number endPosition where to end splicing the array * @returns string[] * * Example: * ```ts * const testArray = ["one", "two", "three"] * spliceArray(testArray, 0, 2) * // => ["three"] * * spliceArray(testArray, testArray.length - 2, 2) * // => ["one"] * ``` */ protected spliceArray(array: string[], startPosition: number, endPosition: number): string[]; /** * Iterates through the selector and tries to find an element or a selector in the first given selector and returns the result as an array * @param cheerio.CheerioAPI $ * @param string selector HTML Selector * @param string elementOrSelector HTML Element or Selector * @param string attribute HTML Attribute * @param string baseUrl baseUrl of the website in case you want to get the relative urls of all products * @returns any[] * * * Example: * ```ts * collectOnAttributeAndElement($, ".results--grid", "a", "href", baseUrl) * // => will return an array containing all relative links in the href attribute that live in a * ``` */ protected collectOnAttributeAndElement($: cheerio.CheerioAPI, selector: string, elementOrSelector: string, attribute: string, baseUrl?: string): any[]; protected collectOnAttributeAndElementWithCallback($: cheerio.CheerioAPI, selector: string, elementOrSelector: string, callback: (_: number, value: any) => void, baseUrl?: string): void; protected splitAndReplaceValue(array: string[], splitter: string, splitIndex: number, valueToReplace: string, replacement: string): number[]; } declare class AmazonPriceSearchEngine extends SearchEngineBase { /** * Scrapes amazon for products based on your search query * @param {string} searchTerm * @returns {ISearchResult[]} */ search(searchTerm: string): Promise; } declare class AmazonPriceSearchEngine2 extends SearchEngineBase { /** * Scrapes amazon for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class EbayPriceSearchEngine extends SearchEngineBase { /** * Scrapes eBay for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class MediaMarktPriceSearchEngine extends SearchEngineBase { /** * Scrapes MediaMarkt for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class SaturnPriceSearchEngine extends SearchEngineBase { /** * Scrapes Saturn for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class SearchEngineList implements ISearchEngine { /** * array of all search engines */ searchEngines: ISearchEngine[]; /** * array of the search engines you wish to iterate through * @param ISearchEngine[] searchEngines */ constructor(searchEngines: ISearchEngine[]); /** * searches for the product through the search engines you defined * @param string searchTerm query of the product name * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class OttoPriceSearchEngine extends SearchEngineBase { /** * Scrapes otto.de for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class ProshopPriceSearchEngine extends SearchEngineBase { /** * Scrapes Proshop.de for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class AlternatePriceSearchEngine extends SearchEngineBase { /** * Scrapes alternate.de for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class KauflandPriceSearchEngine extends SearchEngineBase { /** * Scrapes Kaufland for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class ClevertronicPriceSearchEngine extends SearchEngineBase { /** * Scrapes clevertronic for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class BuecherPriceSearchEngine extends SearchEngineBase { /** * Scrapes bücher.de for products based on your search query * @param string searchTerm */ search(searchTerm: string): Promise; } declare type TSearchEngine = 'Alternate' | 'Amazon' | 'Bücher.de' | 'Clevertronic' | 'Cyberport' | 'Ebay' | 'Kaufland' | 'MediaMarkt' | 'MediMax' | 'Mindfactory' | 'Otto' | 'Proshop' | 'Saturn' | 'All'; declare class SearchEngineFactory { /** * searches for the product through the search engines you defined * @param string searchTerm query of the product name * @returns ISearchResult[] */ GetSearchEngine(searchEngineName: TSearchEngine): ISearchEngine; } declare class CyberportPriceSearchEngine extends SearchEngineBase { /** * Scrapes Cyberport for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class MediMaxPriceSearchEngine extends SearchEngineBase { /** * Scrapes MediMax for products based on your search query * @param string searchTerm * @returns ISearchResult[] */ search(searchTerm: string): Promise; } declare class MindfactoryPriceSearchEngine extends SearchEngineBase { /** * Scrapes Mindfactory for products based on your search query * @param string searchTerm * @returns */ search(searchTerm: string): Promise; } declare class NotebooksbilligerPriceSearchEngine extends SearchEngineBase { search(searchTerm: string): Promise; } export { AlternatePriceSearchEngine, AmazonPriceSearchEngine, AmazonPriceSearchEngine2, BuecherPriceSearchEngine, ClevertronicPriceSearchEngine, ConsoleOutput, CsvOutput, CyberportPriceSearchEngine, EbayPriceSearchEngine, HTTPMethods, IFetchOptions, IOutput, ISearchEngine, ISearchResult, JSONOutput, KauflandPriceSearchEngine, MediMaxPriceSearchEngine, MediaMarktPriceSearchEngine, MindfactoryPriceSearchEngine, NotebooksbilligerPriceSearchEngine, OttoPriceSearchEngine, ProshopPriceSearchEngine, SaturnPriceSearchEngine, SearchEngineBase, SearchEngineFactory, SearchEngineList, SearchResult, TSearchEngine };