-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { SearchEngineBase, SearchResult } from '..'; | ||
import { ISearchResult } from '../../Interfaces'; | ||
|
||
export class CyberportPriceSearchEngine extends SearchEngineBase { | ||
async search(searchTerm: string): Promise<ISearchResult[]> { | ||
const baseUrl = 'https://www.cyberport.de'; | ||
const $ = await this.requestWebsite(`${baseUrl}/tools/search-results.html?q=${encodeURIComponent(searchTerm)}`); | ||
|
||
const result: ISearchResult[] = []; | ||
const titles: any[] = this.collectText($, '.productTitleName'); | ||
const prices: any[] = this.collectText($, '.delivery-price'); | ||
const ratings: any[] = this.collectText($, '.stars'); | ||
const thumbnails: any[] = []; | ||
const links: any[] = this.collectOnAttributeAndElement($, '.productImage', 'a', 'href', baseUrl); | ||
|
||
$('.productImage') | ||
.find('img') | ||
.each((_, value) => { | ||
if ($(value).attr('src')?.startsWith('//')) { | ||
thumbnails.push($(value).attr('src')?.replace('//', 'https://')); | ||
} | ||
}); | ||
|
||
const pricesFilterd = this.splitAndReplaceValue(prices, '€', 1, ',', '.'); | ||
|
||
titles.forEach((title: string, index: number) => { | ||
result.push( | ||
new SearchResult( | ||
this.constructor.name, | ||
links[index], | ||
title, | ||
ratings[index], | ||
pricesFilterd[index], | ||
thumbnails[index] | ||
) | ||
); | ||
}); | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters