2023-04-15 18:24:51 +02:00
|
|
|
import { metaInformation as immoScoutInfo } from '../provider/immoscout.js';
|
|
|
|
|
import { metaInformation as immoNetInfo } from '../provider/immonet.js';
|
2023-03-13 13:42:43 +01:00
|
|
|
import { config } from '../utils.js';
|
2023-04-15 18:24:51 +02:00
|
|
|
|
2023-05-11 11:51:23 +02:00
|
|
|
const additionalImmonetUrlParams = `&wait_for_selector=.content-wrapper-tiles&js_snippet=${Buffer.from(
|
2023-04-15 18:24:51 +02:00
|
|
|
'window.scrollTo(0,document.body.scrollHeight);'
|
|
|
|
|
).toString('base64')}`;
|
|
|
|
|
|
|
|
|
|
const needScrapingAnt = (id) => {
|
|
|
|
|
return id.toLowerCase() === immoScoutInfo.id || id.toLowerCase() === immoNetInfo.id;
|
2021-05-11 11:25:14 +02:00
|
|
|
};
|
2023-03-13 13:42:43 +01:00
|
|
|
export const transformUrlForScrapingAnt = (url, id) => {
|
2023-04-15 18:24:51 +02:00
|
|
|
let urlParams = '';
|
|
|
|
|
if (needScrapingAnt(id)) {
|
|
|
|
|
if (id.toLowerCase() === immoNetInfo.id) {
|
|
|
|
|
urlParams = additionalImmonetUrlParams;
|
|
|
|
|
}
|
|
|
|
|
//only do calls to scrapingAnt when dealing with Immoscout/Immonet
|
|
|
|
|
url = `https://api.scrapingant.com/v2/general?url=${encodeURIComponent(url)}&proxy_type=datacenter${urlParams}`;
|
2021-05-11 11:25:14 +02:00
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
2023-03-13 13:42:43 +01:00
|
|
|
export const isScrapingAntApiKeySet = () => {
|
2021-05-11 11:25:14 +02:00
|
|
|
return config.scrapingAnt != null && config.scrapingAnt.apiKey != null && config.scrapingAnt.apiKey.length > 0;
|
|
|
|
|
};
|
2023-03-13 13:42:43 +01:00
|
|
|
export const makeUrlResidential = (url) => {
|
2022-04-29 13:22:39 +02:00
|
|
|
return url.replace('datacenter', 'residential');
|
|
|
|
|
};
|
2023-04-15 18:24:51 +02:00
|
|
|
export { needScrapingAnt };
|