Skip to content

Commit

Permalink
Added Cyberport support
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Jan 20, 2022
1 parent be83c68 commit 012b82c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 20 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ Just wanted to practice web scraping :)

## Supported online shops:

- eBay
- Amazon
- MediaMarkt
- Saturn
- Proshop.de
- Otto.de
- Alternate
- Kaufland
- Clevertronic
- Bücher.de

- eBay
- Amazon
- MediaMarkt
- MediMax
- Saturn
- Cyberport
- Proshop.de
- Otto.de
- Alternate
- Kaufland
- Clevertronic
- Bücher.de

## Installation

Expand All @@ -28,7 +29,6 @@ npm i more4less

## Importing


### TypeScript

```ts
Expand All @@ -37,7 +37,6 @@ import * as more4less from "more4less";
import { AmazonPriceSearchEngine, EbayPriceSearchEngine } from 'more4less'; // Individual classes
```


### JavaScript

```js
Expand Down Expand Up @@ -125,4 +124,4 @@ Software contributions are welcome. If you are not a dev, testing and reproting

## Questions?

Please open an issue if you have questions, wish to request a feature, etc.
Please open an issue if you have questions, wish to request a feature, etc.
41 changes: 41 additions & 0 deletions src/BL/PriceSearchEngines/CyberportPriceSearchEngine.ts
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;
}
}
20 changes: 14 additions & 6 deletions src/BL/PriceSearchEngines/SearchEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import * as engines from '../index';
export type TSearchEngine =
| 'Alternate'
| 'Amazon'
| 'Bücher.de'
| 'Clevertronic'
| 'Cyberport'
| 'Ebay'
| 'Kaufland'
| 'MediaMarkt'
| 'MediMax'
| 'Otto'
| 'Proshop'
| 'Bücher.de'
| 'All'
| 'Saturn';
| 'Saturn'
| 'All';

export class SearchEngine implements ISearchEngine {
/**
Expand Down Expand Up @@ -50,6 +52,9 @@ export class SearchEngine implements ISearchEngine {
case 'Clevertronic':
result = await new engines.ClevertronicPriceSearchEngine().search(searchTerm);
break;
case 'Cyberport':
result = await new engines.CyberportPriceSearchEngine().search(searchTerm);
break;
case 'Ebay':
result = await new engines.EbayPriceSearchEngine().search(searchTerm);
break;
Expand All @@ -59,14 +64,15 @@ export class SearchEngine implements ISearchEngine {
case 'MediaMarkt':
result = await new engines.MediaMarktPriceSearchEngine().search(searchTerm);
break;
case 'MediMax':
result = await new engines.MediMaxPriceSearchEngine().search(searchTerm);
break;
case 'Otto':
result = await new engines.OttoPriceSearchEngine().search(searchTerm);
break;

case 'Proshop':
result = await new engines.ProshopPriceSearchEngine().search(searchTerm);
break;

case 'Saturn':
result = await new engines.SaturnPriceSearchEngine().search(searchTerm);
break;
Expand All @@ -84,7 +90,9 @@ export class SearchEngine implements ISearchEngine {
new engines.OttoPriceSearchEngine().search(searchTerm),
new engines.ProshopPriceSearchEngine().search(searchTerm),
new engines.SaturnPriceSearchEngine().search(searchTerm),
new engines.BuecherPriceSearchEngine().search(searchTerm)
new engines.BuecherPriceSearchEngine().search(searchTerm),
new engines.CyberportPriceSearchEngine().search(searchTerm),
new engines.MediMaxPriceSearchEngine().search(searchTerm)
]);
result = getAll.flat(1);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/BL/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export * from './PriceSearchEngines/KauflandPriceSearchEngine';
export * from './PriceSearchEngines/ClevertronicPriceSearchEngine';
export * from './PriceSearchEngines/BuecherPriceSearchEngine';
export * from './PriceSearchEngines/SearchEngine';
export * from './PriceSearchEngines/CyberportPriceSearchEngine';
export * from './PriceSearchEngines/MediMaxPriceSearchEngine';

0 comments on commit 012b82c

Please sign in to comment.